从另一个文件创建 mdiArea 子窗口

2024-09-22 16:33:13 发布

您现在位置:Python中文网/ 问答频道 /正文

在主窗口类的mdiArea中创建子窗口(应该在不同的Python文件中创建)时遇到了问题。你知道吗

我的_应用程序类型

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

# importing my main app GUI
from GUIs import main_window_GUI

# importing different application modules
from Modules import login_module
from Modules.diagnostic_center_module import Diagnostic_center

class My_app(QMainWindow, main_window_GUI.Ui_main_window):
    def __init__(self):
        QMainWindow.__init__(self)
        main_window_GUI.Ui_main_window.__init__(self)
        self.setupUi(self)

        # Now I'm calling a function from *diagnostic_center_module*
        # in order to create and show a sub window within 
        # mdiArea (which is a part of Ui_main_window) called *body*
        self.show_diagnostic_center

诊断中心_模块.py

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

# importing my sub window GUI
from GUIs import diagnostic_center_GUI

class Diagnostic_center(object):
    def show_diagnostic_center(self):
        self.diagnostic_center_subwindow = QWidget
        self.diagnostic_center_subwindow.setObjectName("diagnostic_center_subwindow")
        self.container = QFrame(self.diagnostic_center_subwindow)

        diagnostic_GUI = diagnostic_center_GUI.Ui_diagnostic_center()
        diagnostic_GUI.setupUi(diagnostic_GUI)

        self.container.setCurrentWidget(diagnostic_GUI)

        # this part should create a sub window within mdiArea called body
        # whic is located inside My_app.py file.
        self.body.addSubWindow(self.diagnostic_center_subwindow)
        self.diagnostic_center_subwindow.showNormal()

我指望你的人帮我解决这个问题。提前多谢了。你知道吗


Tags: fromimportselfappuimainguiwindow