python之PySide2安装使⽤及QTDesignerUI设计案例教程pyside2
>>> pip install 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\
Unable to lanch C:
PySide2⽬录下复制到新建的bin⽂件夹
C:\...\Python\Python39\site-packages\PySide2\
Ⅰ. Init
from PySide2.QtWidgets import *
class Window:
def __init__(self):
python安装教程非常详细self.win = QMainWindow()
if __name__ == '__main__':
app = QApplication([])
w = Window()
w.win.show()
<_()
from PySide2.QtWidgets import *
if __name__ == '__main__':
app = QApplication([])
win = QMainWindow()
win.show()
<_()
Ⅱ Example
from PySide2.QtWidgets import *
class Window:
def __init__(self):
self.win = QMainWindow()
size(500, 400)
ve(700, 210)
self.win.setWindowTitle("测试窗⼝")
self.button = QPushButton("button", self.win)
ve(300, 100)
self.t(self.btnClick)
def btnClick(self):
info = PlainText()  # 获取⽂本信息
# print("button被点击")
if __name__ == '__main__':
app = QApplication([])
# win = QMainWindow()
# win.show()
w = Window()
w.win.show()
<_()
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()
<_()
2.动态加载ui⽂件
from PySide2.QtWidgets import *
from PySide2.QtCore import QFile
from PySide2.QtUiTools import QUiLoader
def __init__(self):
super(Window, self).__init__()
# 从⽂件中加载UI定义
qfile = QFile("demo1.ui")
qfile.open(QFile.ReadOnly)
qfile.close()
# 从UI定义中动态创建⼀个相应的窗⼝对象, 将其内部⽂件定义为self.ui.button
self.ui = QUiLoader().load(qfile)
self.ui.t(self.btnClick)
# self.t(self.btnClick)
def btnClick(self):
info = PlainText()  # 获取⽂本信息
# info = PlainText()
print(info)
if __name__ == '__main__':
app = QApplication([])
w = Window()
w.ui.show()
# w.win.show()
<_()
到此这篇关于python之PySide2安装使⽤及QT Designer UI设计案例教程的⽂章就介绍到这了,更多相关python之PySide2安装使⽤及QT Designer UI设计内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。