pyside2
QT Designer
>>> pip show pyside2
Location: c:\users\Administrator\appdata\roaming\python\python39\site-packages
文件位置
C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\PySide2\designer.exe
Unable to lanch C:
PySide2目錄下復(fù)制uic.exe到新建的bin文件夾
C:\...\Python\Python39\site-packages\PySide2\bin\uic.exe
Ⅰ. Init
from PySide2.QtWidgets import *
class Window:
def __init__(self):
self.win = QMainWindow()
if __name__ == '__main__':
app = QApplication([])
w = Window()
w.win.show()
app.exec_()
from PySide2.QtWidgets import *
if __name__ == '__main__':
app = QApplication([])
win = QMainWindow()
win.show()
app.exec_()
Ⅱ Example
from PySide2.QtWidgets import *
class Window:
def __init__(self):
self.win = QMainWindow()
self.win.resize(500, 400)
self.win.move(700, 210)
self.win.setWindowTitle("測試窗口")
self.textEdit = QTextEdit(self.win)
self.textEdit.move(50, 50)
self.textEdit.resize(200, 300)
self.textEdit.setPlaceholderText("請輸入文本")
self.button = QPushButton("button", self.win)
self.button.move(300, 100)
self.button.clicked.connect(self.btnClick)
def btnClick(self):
info = self.textEdit.toPlainText() # 獲取文本信息
print(info)
# print("button被點(diǎn)擊")
if __name__ == '__main__':
app = QApplication([])
# win = QMainWindow()
# win.show()
w = Window()
w.win.show()
app.exec_()
QT Designer
1.自動生成代碼
...
from PySide2.QtCore import QFile
from PySide2.QtUiTools import QUiLoader
...
if __name__ == "__main__":
app = QApplication([])
win = QMainWindow()
w = Ui_Form()
w.setupUi(win)
win.show()
app.exec_()
2.動態(tài)加載ui文件
from PySide2.QtWidgets import *
from PySide2.QtCore import QFile
from PySide2.QtUiTools import QUiLoader
class Window:
def __init__(self):
super(Window, self).__init__()
# 從文件中加載UI定義
qfile = QFile("demo1.ui")
qfile.open(QFile.ReadOnly)
qfile.close()
# 從UI定義中動態(tài)創(chuàng)建一個相應(yīng)的窗口對象, 將其內(nèi)部文件定義為self.ui.button
self.ui = QUiLoader().load(qfile)
self.ui.button.clicked.connect(self.btnClick)
# self.button.clicked.connect(self.btnClick)
def btnClick(self):
info = self.ui.textEdit.toPlainText() # 獲取文本信息
# info = self.textEdit.toPlainText()
print(info)
if __name__ == '__main__':
app = QApplication([])
w = Window()
w.ui.show()
# w.win.show()
app.exec_()
到此這篇關(guān)于python之PySide2安裝使用及QT Designer UI設(shè)計案例教程的文章就介紹到這了,更多相關(guān)python之PySide2安裝使用及QT Designer UI設(shè)計內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- python GUI庫圖形界面開發(fā)之PyQt5 Qt Designer工具(Qt設(shè)計師)詳細(xì)使用方法及Designer ui文件轉(zhuǎn)py文件方法
- PyQt 圖解Qt Designer工具的使用方法
- 詳解PyCharm+QTDesigner+PyUIC使用教程
- Qt Designer的簡單使用方法