def main(): window = QMainWindow() window.setGeometry(100, 100, 800, 600) window.setAttribute() # 设置window背景 palette = QPalette() picture = QPixmap('背景.jpg') palette.setBrush(window.backgroundRole(), QBrush(picture)) window.setPalette(palette) button = QtWidgets.QPushButton(window) button.setText('button') button.setGeometry(200, 100, 100, 50) label = QtWidgets.QLabel(window) label.setText('23456789') label.setGeometry(200, 200, 200, 50) # 设置标签颜色 label.setAutoFillBackground(True) pale = QPalette() pale.setColor(QPalette.Window, Qt.yellow) pale.setColor(QPalette.WindowText, Qt.red) label.setPalette(pale) # 设置标签颜色完毕 # 设置字体 label.setFont(QFont('Microsoft YaHei UI', 20, QFont.Bold)) combobox = QtWidgets.QComboBox(window) combobox.setGeometry(200, 300, 100, 50) combobox.addItem('A') combobox.addItem('B') combobox.currentText() lineEdit = QtWidgets.QLineEdit(window) lineEdit.setGeometry(200, 400, 100, 50) lineEdit.setText('abcd') lineEdit.text() def show_time(): label.setText(change()) button.clicked.connect(show_time) combobox.currentIndexChanged.connect(change) button.setDisabled(False) window.show() return app.exec_()
window.move(100, 100) # 设置当前窗口的名称 window.setWindowTitle('我的第一个pyqt程序') # 引入QIcon模块 from PyQt5.QtGui import * # 创建icon图标对象 icon = QIcon('1.png') # 设置当前窗口的图标 window.setWindowIcon(icon) # 创建QPalette调色板对象 palette = QPalette() # 设置调色板颜色 # 1.要设置的对象的某个颜色属性 # 2.QColor要设置的颜色值 RGB(红绿蓝) 0~255 palette.setColor(window.backgroundRole(), QColor(0, 0, 0)) # 设置背景图片 palette.setBrush(window.backgroundRole(), QBrush(QPixmap('icon.png'))) # 设置当前窗口的背景颜色 window.setPalette(palette) # 展示窗口 window.show() # 执行应用程序 app.exec_() # 当程序退出时,结束该程序进程 sys.exit(app.exec_()) # 加警告框, from PyQt5.QtWidgets import QMessageBox # 1.要给谁添加这个警告框 # 2.警告框的标题