PyQt5主窗口動態(tài)加載Widget實例代碼
本文研究的主要是PyQt5主窗口動態(tài)加載Widget的代碼示例,具體如下。
我們通過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) #在狀態(tài)欄顯示文件地址 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主窗口動態(tài)加載Widget實例代碼的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!
相關文章
python使用aiohttp通過設置代理爬取基金數(shù)據(jù)簡單示例
這篇文章主要為大家介紹了python使用aiohttp通過設置代理爬取基金數(shù)據(jù)簡單示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-06-06詳解Python圖像形態(tài)學處理(開運算,閉運算,梯度運算)
數(shù)學形態(tài)學(Mathematical Morphology)是一種應用于圖像處理和模式識別領域的新方法。本文將為大家介紹Python圖像形態(tài)學處理中的開運算、閉運算和梯度運算,感興趣的可以了解一下2022-06-06Pandas設置DataFrame的index索引起始值為1的兩種方法
DataFrame中的index索引列默認是從0開始的,那么我們?nèi)绾卧O置index索引列起始值從1開始呢,本文主要介紹了Pandas設置DataFrame的index索引起始值為1的兩種方法,感興趣的可以了解一下2024-07-07flask/django 動態(tài)查詢表結構相同表名不同數(shù)據(jù)的Model實現(xiàn)方法
今天小編就為大家分享一篇flask/django 動態(tài)查詢表結構相同表名不同數(shù)據(jù)的Model實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08