PyQt5主窗口动态加载Widget实例代码,pyqt5widget,它是Python编程
PyQt5主窗口动态加载Widget实例代码,pyqt5widget,它是Python编程
PyQt是一个创建GUI应用程序的工具包。它是Python编程语言和Qt库的成功融合。Qt库是目前最强大的库之一。PyQt是由Phil Thompson 开发。
我们通过Qt Designer设计两个窗口,命名为主窗口(MainForm)和子窗口(ChildrenForm)。我们在主窗口的空白中央添加一个栅格布局并命名为MaingridLayout,等会需要将ChildrenForm放进去。
编写代码
from PyQt5 import QtWidgets from MainForm import Ui_MainForm from Children import Ui_Form from PyQt5.QtWidgets import QFileDialog class MainForm(QtWidgets.QMainWindow,Ui_MainForm): def __init__(self): super(MainForm,self).__init__() self.setupUi(self) self.child=ChildrenForm() #self.child = children()生成子窗口实例self.child self.fileOpen.triggered.connect(self.openMsg) #菜单的点击事件是triggered self.fileClose.triggered.connect(self.close) self.actionTst.triggered.connect(self.childShow) #点击actionTst,子窗口就会显示在主窗口的MaingridLayout中 def childShow(self): self.MaingridLayout.addWidget(self.child) #添加子窗口 self.child.show() def openMsg(self): file,ok=QFileDialog.getOpenFileName(self,"打开","C:/","All Files (*);;Text Files (*.txt)") self.statusbar.showMessage(file) #在状态栏显示文件地址 class ChildrenForm(QtWidgets.QWidget,Ui_Form): def __init__(self): super(ChildrenForm,self).__init__() self.setupUi(self) if __name__=="__main__": import sys app=QtWidgets.QApplication(sys.argv) myshow=MainForm() myshow.show() sys.exit(app.exec_())
以上就是本文关于PyQt5主窗口动态加载Widget实例代码的全部内容,希望对大家有所帮助。
相关内容
- 使用PyQt来编写第一个Python GUI程序,pyqtpython,未经许可,
- 使用PyQt来编写第一个Python GUI程序,pyqtpython,未经许可,
- 使用HTML/CSS/JS开发桌面程序(基于QWebkit),cssqwebkit,s
- 基于PyQt的Python识别Access密码,pyqtpythonaccess,[Python]代码
- PyQt写的浏览单web页面的browser,pyqtbrowser,程序代码#!/u
- PyQt5打开文件对话框QFileDialog实例代码,pyqt5qfiledialog
- PyQt5主窗口动态加载Widget实例代码,pyqt5widget
- Python3使用PyQt5制作简单的画板/手写板实例,python3pyqt
- python使用pyqt写带界面工具的示例代码,pythonpyqt
- python+pyqt实现12306图片验证效果,
评论关闭