0

I am creating a program with Python 2.7, and have run into a problem that hours of searching Google and the forums have not answered.

My program consists of a Main_Window called sessions_window.py that holds a Tab Widget. Within each tab, there should contain a separate Main Window File. For example, one tab of sessions_window.py is the account tab, and I have another acount1.py file that contains account information, which I want to embed in the account tab (and yes, I know I spelled account "acount", I will fix later). Another tab will be called Graph, and should contain another Graph.py file (although I have not gotten to this point yet).

*As a note, I have named my elements according to an index/description system, so they are a little long and funky but it helps me.

I have successfully created the files, but am stuck on embedding them into the session_window.py tabs.

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_())

I have imported the files, created a grid for the tab, and tried to addWidget to grid. but I get the error below.

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

I also tried

self.accountTabImport = acount1.Ui_MainWindow()

with the same error message.

I also tried to skip out on defining as above and just include

self.gridLayout_AccountTab.addWidget(acount1.Ui_MainWindow).

same error.

the acount1.py contains a class which holds a bunch of functions. Dont see the need to include it here, but if it is needed let me know. Any help would be greatly appreciated.

ksmith
  • 23
  • 5

1 Answers1

0

You need to instantiate the class first (create an object/instance from the class)

self.accountTabImport = acount1.Ui_MainWindow()

(note the brackets at the end)

Note that you may also need to provide arguments to the above call, depening on what is in the method signature of Ui_MainWindow.__init__

three_pineapples
  • 11,579
  • 5
  • 38
  • 75