1初始化界面
from PyQt5.QtWidgets import QLabel, QWidget
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtGui import QPainter, QColor, QIcon, QPixmap
import sys
class My_UI(QWidget):
def __init__(self,rstpadd=None,parent=None):
super(My_UI, self).__init__(parent)
self.setGeometry(2, 30, 1920, 1020) #界面左上角坐标 以及 界面长宽
self.show()
def main():
app = QtWidgets.QApplication(sys.argv)
UI = My_UI()
UI.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
界面背景颜色
from PyQt5.QtWidgets import QLabel, QWidget
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtGui import QPainter, QColor, QIcon, QPixmap
import sys
class My_UI(QWidget):
def __init__(self,rstpadd=None,parent=None):
super(My_UI, self).__init__(parent)
self.palette1 = QtGui.QPalette()
self.palette1.setColor(self.backgroundRole(), QColor(10, 220, 20)) # 背景颜色
self.setPalette(self.palette1)
self.setGeometry(2, 30, 1000, 800) #界面左上角坐标 以及 界面长宽
self.show()
def main():
app = QtWidgets.QApplication(sys.argv)
UI = My_UI()
UI.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
隐藏边框
设置背景图片
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QLabel, QWidget
from PyQt5 import QtWidgets, QtGui
import sys
class My_UI(QWidget):
def __init__(self,rstpadd=None,parent=None):
super(My_UI, self).__init__(parent)
self.palette1 = QtGui.QPalette()
# self.palette1.setColor(self.backgroundRole(), QColor(10, 220, 20)) # 背景颜色
self.palette1.setBrush(QtGui.QPalette.Background, QtGui.QBrush(QtGui.QPixmap("ddd.jpg")))#背景图片
self.setPalette(self.palette1)
self.setWindowFlag(Qt.FramelessWindowHint) #隐藏边框
self.setGeometry(200, 300, 473, 643) #界面左上角坐标 以及 界面长宽
self.show()
def main():
app = QtWidgets.QApplication(sys.argv)
UI = My_UI()
UI.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
字体以及文字显示
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QLabel, QWidget
from PyQt5 import QtWidgets, QtGui
import sys
class My_UI(QWidget):
def __init__(self,rstpadd=None,parent=None):
super(My_UI, self).__init__(parent)
self.font = QtGui.QFont()
self.font.setFamily("Arial")#字体
self.font.setPointSize(15)#字号
self.t = QtWidgets.QLabel(self)
self.t.setText("字体")
self.t.setFont(self.font)
self.t.setGeometry(200, 100, 100, 50)#位置
self.t.setStyleSheet("color:rgb({},{},{},255)".format(255, 128, 0)) #颜色
self.setGeometry(200, 300, 473, 643) #界面左上角坐标 以及 界面长宽
self.show()
def main():
app = QtWidgets.QApplication(sys.argv)
UI = My_UI()
UI.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
按钮显示
按钮点击事件
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QLabel, QWidget
from PyQt5 import QtWidgets, QtGui
import sys
class My_UI(QWidget):
def __init__(self,rstpadd=None,parent=None):
super(My_UI, self).__init__(parent)
self.font = QtGui.QFont()
self.font.setFamily("Arial")#字体
self.font.setPointSize(15)#字号
self.btma = QtWidgets.QPushButton(self)
self.btma.setText("按钮A")
self.btma.setFont(self.font)
self.btma.setGeometry(180, 100, 100, 50)
self.btma.clicked.connect(self.clicked_btm)#点击触发函数
self.setGeometry(200, 300, 473, 643) #界面左上角坐标 以及 界面长宽
self.show()
def clicked_btm(self):
self.t = QtWidgets.QLabel(self)
self.t.setText("字体")
self.t.setFont(self.font)
self.t.setGeometry(200, 200, 100, 50) # 位置
self.t.setStyleSheet("color:rgb({},{},{},255)".format(255, 128, 0)) # 颜色
self.t.show()#显示
def main():
app = QtWidgets.QApplication(sys.argv)
UI = My_UI()
UI.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QLabel, QWidget
from PyQt5 import QtWidgets, QtGui
import sys
class My_UI(QWidget):
def __init__(self,rstpadd=None,parent=None):
super(My_UI, self).__init__(parent)
self.font = QtGui.QFont()
self.font.setFamily("Arial")#字体
self.font.setPointSize(15)#字号
self.btma = QtWidgets.QPushButton(self)
self.btma.setStyleSheet("QPushButton{background-image: url(kaishi.png)}")#设置图片
self.btma.setFont(self.font)
self.btma.setGeometry(180, 100, 100, 50)
self.btma.clicked.connect(self.clicked_btm)#点击触发函数
self.setGeometry(200, 300, 473, 643) #界面左上角坐标 以及 界面长宽
self.show()
def clicked_btm(self):
self.t = QtWidgets.QLabel(self)
self.t.setText("字体")
self.t.setFont(self.font)
self.t.setGeometry(200, 200, 100, 50) # 位置
self.t.setStyleSheet("color:rgb({},{},{},255)".format(255, 128, 0)) # 颜色
self.t.show()#显示
def main():
app = QtWidgets.QApplication(sys.argv)
UI = My_UI()
UI.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
输入框
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QLabel, QWidget,QLineEdit
from PyQt5 import QtWidgets, QtGui
import sys
class My_UI(QWidget):
def __init__(self,rstpadd=None,parent=None):
super(My_UI, self).__init__(parent)
self.font = QtGui.QFont()
self.font.setFamily("Arial")#字体
self.font.setPointSize(15)#字号
self.line = QLineEdit(self)
self.line.setFont(self.font)
self.line.setGeometry(200, 100, 100, 50)
self.line.setStyleSheet(
'border-width: 1px;border-style: solid;border-color: rgb(255, 0, 0);background-color: rgb(255,255,255);color:rgb(0, 255, 0)')#输入框样式设置
self.btma = QtWidgets.QPushButton(self)
self.btma.setText("按钮A")
self.btma.setFont(self.font)
self.btma.setGeometry(180, 200, 100, 50)
self.btma.clicked.connect(self.clicked_btm)#点击触发函数
self.setGeometry(200, 300, 473, 643) #界面左上角坐标 以及 界面长宽
self.show()
def clicked_btm(self):
self.t = QtWidgets.QLabel(self)
self.t.setText(self.line.text()) #显示输入框里面的文字
self.t.setFont(self.font)
self.t.setGeometry(200, 300, 100, 50) # 位置
self.t.setStyleSheet("color:rgb({},{},{},255)".format(255, 128, 0)) # 颜色
self.t.show()#显示
def main():
app = QtWidgets.QApplication(sys.argv)
UI = My_UI()
UI.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()