国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

PyQt5主窗口動態(tài)加載Widget實例代碼

2020-02-22 23:09:13
字體:
來源:轉載
供稿:網(wǎng)友

本文研究的主要是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實例代碼的全部內容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 白城市| 永城市| 清丰县| 温宿县| 泸定县| 乐昌市| 拉萨市| 上林县| 那坡县| 逊克县| 河西区| 呼图壁县| 高碑店市| 永顺县| 库尔勒市| 临沭县| 扶绥县| 澄江县| 精河县| 勃利县| 临泉县| 新建县| 常州市| 哈尔滨市| 永春县| 正定县| 宁强县| 四川省| 河北省| 安平县| 丹寨县| 德保县| 崇礼县| 韶山市| 珠海市| 定安县| 双柏县| 德令哈市| 若羌县| 庆城县| 沾益县|