Python 2.7 PyQt4将主窗口文件添加到另一个主窗口的选项卡

Python 2.7 PyQt4将主窗口文件添加到另一个主窗口的选项卡

问题描述:

我正在用Python 2.7创建一个程序,并且遇到了几小时搜索Google和论坛未回答的问题。Python 2.7 PyQt4将主窗口文件添加到另一个主窗口的选项卡

我的程序由一个名为sessions_window.py的Main_Window组成,它包含一个Tab Widget。在每个选项卡中,应该包含一个单独的主窗口文件。例如,sessions_window.py的一个选项卡是帐户选项卡,并且我有另一个包含帐户信息的acount1.py文件,我想将它嵌入帐户选项卡(并且是的,我知道我拼写帐户“acount”,I稍后会修复)。另一个选项卡将被称为Graph,并且应该包含另一个Graph.py文件(尽管我还没有得到这一点)。 *作为一个说明,我已经根据索引/描述系统对我的元素进行了命名,所以它们有点长而且时髦,但它对我有帮助。

我已经成功创建了这些文件,但我坚持将它们嵌入到session_window.py选项卡中。

from PyQt4.QtCore import * 
from PyQt4.QtGui import * 

import acount1 

class Ui_BxSession(object): 

    def configurePageB(self, BxSession): 

     self.accountTabImport = acount1.Ui_MainWindow 

# B : Session Page 
     BxSession.setObjectName("BxSession") 
     BxSession.resize(800, 600) 

# B_cn1 : Main Space Container 

     self.B_cn1xMainSpace = QWidget(BxSession) 
     self.B_cn1xMainSpace.setObjectName("B_cn1xMainSpace") 

     self.gridLayout_MainB = QGridLayout(self.B_cn1xMainSpace) 
     self.gridLayout_MainB.setObjectName("gridLayout_MainB") 

     BxSession.setCentralWidget(self.B_cn1xMainSpace) 

# B_cn1_cn1 : Tab Window Space Container 

     self.B_cn1_cn1xTabWindowSpace = QTabWidget(self.B_cn1xMainSpace) 
     self.B_cn1_cn1xTabWindowSpace.setObjectName("B_cn1_cn1xTabWindowSpace") 

     self.gridLayout_MainB.addWidget(self.B_cn1_cn1xTabWindowSpace) 

# B_cn1_cn1_tb1 : Account Tab 

     self.B_cn1_cn1_tb1xAccount = QWidget(self.B_cn1_cn1xTabWindowSpace) 
     self.B_cn1_cn1_tb1xAccount.setObjectName("B_cn1_cn1_tb1xAccount") 

     self.B_cn1_cn1xTabWindowSpace.addTab(self.B_cn1_cn1_tb1xAccount, "Account") 

     self.gridLayout_AccountTab = QGridLayout(self.B_cn1_cn1_tb1xAccount) 
     self.gridLayout_AccountTab.setObjectName("gridLayout_AccountTab") 



     self.gridLayout_AccountTab.addWidget(self.accountTabImport) 



# B_cn1_cn1_tb2 : Session Tab 

     self.B_cn1_cn1_tb2xSession1 = QWidget(self.B_cn1_cn1xTabWindowSpace) 
     self.B_cn1_cn1_tb2xSession1.setObjectName("B_cn1_cn1_tb2xSession1") 

     self.B_cn1_cn1xTabWindowSpace.addTab(self.B_cn1_cn1_tb2xSession1, "Session") 

### rest of code left out 

if __name__ == "__main__": 
import sys 
app = QApplication(sys.argv) 
BxSession = QMainWindow() 
ui = Ui_BxSession() 
ui.configurePageB(BxSession) 
BxSession.show() 
sys.exit(app.exec_()) 

我已导入的文件,创造了标签的网格,并试图addWidget电网。但我得到下面的错误。

C:\Python27\python.exe "C:/Users/smiths/Desktop/App  Project/AppDev_2/rewritecode/program/session_window.py" 
Traceback (most recent call last): 
File "C:/Users/smiths/Desktop/App Project/AppDev_2/rewritecode/program/session_window.py", line 139, in <module> 
ui.configurePageB(BxSession) 
File "C:/Users/smiths/Desktop/App Project/AppDev_2/rewritecode/program/session_window.py", line 50, in configurePageB 
self.gridLayout_AccountTab.addWidget(self.accountTabImport) 
TypeError: arguments did not match any overloaded call: 
QGridLayout.addWidget(QWidget): argument 1 has unexpected type 'type' 
QGridLayout.addWidget(QWidget, int, int, Qt.Alignment alignment=0): argument 1 has unexpected type 'type' 
QGridLayout.addWidget(QWidget, int, int, int, int, Qt.Alignment alignment=0): argument 1 has unexpected type 'type' 

Process finished with exit code 1 

我还试图

self.accountTabImport = acount1.Ui_MainWindow() 

具有相同的错误消息。

我还试图跳过列于如上述定义,只是包括

self.gridLayout_AccountTab.addWidget(acount1.Ui_MainWindow). 

同样的错误。

acount1.py包含一个包含一堆函数的类。不要看到需要在这里包括它,但如果需要的话让我知道。任何帮助将不胜感激。

您需要先实例化类(创建一个对象从类/实例)

self.accountTabImport = acount1.Ui_MainWindow() 

(注意最后括号),您可能还需要提供参数

注上述呼吁,取决于方法签名中的内容Ui_MainWindow.__init__