PySide文档阅读笔记-第一个Qt for Python程序
生活随笔
收集整理的這篇文章主要介紹了
PySide文档阅读笔记-第一个Qt for Python程序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
想使用Qt for Python要2個條件:
1.Python 3.5以后的版本(包括3.5);
2.libclang 3.9以后的版本(包括3.9);
輸入這條命令進行安裝;
python -m pip install --index-url=http://download.qt.io/snapshots/ci/pyside/5.11/latest pyside2 --trusted-host download.qt.io程序運行截圖如下:
安裝python 使用pip 安裝Qt
?
安裝libclang 3.9以后的版本:
他有個選項,是加到環境變量里面,不會配的同學一定要選擇,加到環境變量里面;
?
搞好了,建立一個py文件,測試如下代碼:
import PySide2.QtCoreprint(PySide2.QtCore.qVersion())運行截圖如下:
?
再來一套測試代碼:
代碼如下:
import sys import randomfrom PySide2 import QtCore, QtWidgets, QtGuiclass MyWidget(QtWidgets.QWidget):def __init__(self):super().__init__()self.hello = ["Hallo Welt", "你好,世界", "Hei maailma",\"Hola Mundo", "Привет мир"]self.button = QtWidgets.QPushButton("Click me!")self.text = QtWidgets.QLabel("Hello World")self.text.setAlignment(QtCore.Qt.AlignCenter)self.text.setFont(QtGui.QFont("Titillium", 30))self.button.setFont(QtGui.QFont("Titillium", 20))self.layout = QtWidgets.QVBoxLayout()self.layout.addWidget(self.text)self.layout.addWidget(self.button)self.setLayout(self.layout)self.button.clicked.connect(self.magic)def magic(self):self.text.setText(random.choice(self.hello))if __name__ == "__main__":app = QtWidgets.QApplication([])widget = MyWidget()widget.resize(800, 600)widget.show()sys.exit(app.exec_())運行截圖如下:
總結
以上是生活随笔為你收集整理的PySide文档阅读笔记-第一个Qt for Python程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux学习笔记-Makefile中的
- 下一篇: Python工作笔记-dictionar