python3.6 & pyQt5 & QtDesigner 简易入门教程

'''
python3.6 & pyQt5 & QtDesigner 简易入门教程
    
1. python 官网下载安装python3.6并配置好环境;


2.cmd下 运行:

pip install PyQt5   安装PyQt库;


3.cmd下运行:

pip3.6 install PyQt5-tools 安装QtDesigner

QtDesigner一般默认被安装到Python36\Lib\site-packages\pyqt5-tools路径下。

安装成功后在此路径下打开designer.exe即可进行QT界面的设计。

设计完成后保存为.ui格式文件。其实.ui文件就是一个xml文件,里面有界面元素的各种信息。

然后在python代码中使用loadUi()函数加载ui文件。这个过程其实是解析xml文件并转译为python程序对象的过程。

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.uic import loadUi
	
class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        loadUi('qtdesigner.ui', self)
        self.pushButton.clicked.connect(self.say)
		
    def say(self):        
        self.label.setText("哈哈哈")
        print("哈哈哈")

app = QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec())

加载后界面内的各种对象都可以被python程序代码调用,属性也可以动态改变。对象的事件也可以绑定程序。

'''

猜你喜欢

转载自blog.csdn.net/MAILLIBIN/article/details/82501505