问题描述
我是 Python 的初学者,但我来自 Java 和 Android 的 OOPS 概念足够强大,足以激励我在 Python 中制作一些工具.我正在使用 PyQt 来开发应用程序.在我的应用程序中,使用了很多 QTabWidget,并且在每个 TAB 小部件中都有很多 UI 控件.请参阅相同的屏幕截图.
I am a beginner in python but my OOPS concept from Java and Android are strong enough to motivate me in making some tool in python.I am using PyQt for developing the application. In my application there are lot of QTabWidget used and has lot of UI controls in each TAB widget. Please see the screenshot for the same.
我将整个工具的所有事件控制都保存在一个文件中,但现在我想根据每个 QTab 的一个单独的 Python 文件将其隔离,以便在 Tab 中进行事件控制.
All of the event control of entire tool i have kept in one single file but now i want to segregate it based on one individual python file per QTab for event control inside the Tab.
我的项目文件架构如下:
My project file architecture looks like :
我知道这将是一件非常简单的事情,但考虑到我使用 Python 的经验,我发现这很困难.我非常感谢带有代码片段的示例.由于我能够从单独的文件中控制真正复杂的 QThread,但无法了解如何为 Ui 控件执行此操作.
I know this would be some really easy thing but considering my experience with Python i am finding it difficult. I would really appreciate example with code snippet. Since i am able to control real complicated QThread from seperate files but not able get how to do it for Ui controls.
我尝试为它制作一个文件,就像我为 Thread 类制作的那样,但最终将参数传递给了 super
I tried making a file for it like i made for Thread classes but end up with argument passing expection to super
from generated.MainGUI import Ui_MainWindow
class SemiAuto_Create_Load(QtGui.QMainWindow):
def __init__(self,parent=none):
super(SemiAuto_Create_Load, self).__init__()
self.ui = Ui_MainWindow
self.ui.setupUi(self)
self.connectControlEvents()
尝试过:self.sacl = SemiAuto_Create_Load()
异常:
TypeError: init() 只需要 3 个参数(给定 1 个)
TypeError: init() takes exactly 3 arguments (1 given)
推荐答案
好的,我在
Mainwindow.py
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
super(MainWindow, self).__init__(parent)
Profile().notify(None)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.connectButtons()
SemiAuto_Create_Load(self, self.ui)
还有
SemiAuto_Create_Load
class SemiAuto_Create_Load(QtGui.QMainWindow):
def __init__(self, parent, ui):
super(SemiAuto_Create_Load, self).__init__(parent)
self.ui = ui
self.connectControlEvents()
def connectControlEvents(self):
self.ui.load_vsa_radio.clicked.connect(self.onLoad_vsa_radio)
self.ui.create_vsa_radio.clicked.connect(self.onCreate_vsa_radio)
问题是在 init() 中与 parent 传递参数并试图直接获取 MainGUI 的对象而不是作为来自 MainWindow 的参数
Problem was passing the parameter with parent in init() and trying to get the object of MainGUI directly instead of as a parameter from MainWindow
这篇关于PyQt UI 事件控件隔离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!