# -*- coding: utf-8 -*-
from PySide2 import QtWidgets, QtGui
import sys
class ButtonApp(QtWidgets.QMainWindow):
def __init__(self):
'''
州的先生 https://zmister.com
'''
super(ButtonApp, self).__init__()
self.setWindowTitle("Qt For Python按钮控件 | 州的先生")
self.setFixedSize(500, 200) # 设置窗口固定大小
self.main_widget = QtWidgets.QWidget()
self.main_layout = QtWidgets.QVBoxLayout()
self.main_widget.setLayout(self.main_layout)
self.btn_1 = QtWidgets.QPushButton("按钮一")
self.btn_2 = QtWidgets.QPushButton()
self.btn_2.setText("按钮二")
self.btn_3 = QtWidgets.QPushButton("按钮三") # 创建按钮3
icon_img = QtGui.QIcon(r"D:\Users\Desktop\38944.ico") # 实例化一个QIcon对象
self.btn_3.setIcon(icon_img) # 设置按钮的图标
self.main_layout.addWidget(self.btn_1)
self.main_layout.addWidget(self.btn_2)
self.main_layout.addWidget(self.btn_3)
self.setCentralWidget(self.main_widget)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
gui = ButtonApp()
gui.show()
sys.exit(app.exec_())
上一篇
使用label显示图片
2024-05-08
下一篇
pyside常用命令
2024-05-08