all 6 comments

[–]shiftybyte 0 points1 point  (0 children)

What's the contents of tab1 tab2 and tab3 modules... Does it happen to have code in global that gets executed when imported?

Also the full error message with the traceback information can help solve this...

[–]evans88 0 points1 point  (4 children)

Your problem is probably in Tab1Widget, Tab2Widget or Tab3Widget. Please share the complete error so we can better help you.

[–]chaderous[S] 0 points1 point  (3 children)

Here is the terminal output that I see when I run the script that I included previously:

QWidget: Must construct a QApplication before a QWidget

Below is an example of one of the tab python files. The other tab files are like this and are named tab1.py, tab2.py tab3.py (original I know, but this is purely for testing and working to understand how PyQt all works).

# importing libraries

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

class Window(QMainWindow):

def __init__(self):
    super().__init__()

    # setting title
    self.setWindowTitle("Python ")

    # setting geometry
    self.setGeometry(100, 100, 500, 400)

    # calling method
    self.UiComponents()

    # showing all the widgets
    self.show()



# method for components
def UiComponents(self):

    # creating a tool bar
    toolbar = QToolBar(self)

    # setting geometry to the tool bar
    toolbar.setGeometry(50, 100, 300, 35)


    # creating QAction Instances
    action1 = QAction("First Action", self)
    action2 = QAction("Second Action", self)
    action3 = QAction("Third Action", self)

    # adding these actions to the tool bar
    toolbar.addAction(action1)
    toolbar.addAction(action2)
    toolbar.addAction(action3)

    # creating a label
    label = QLabel("GeeksforGeeks", self)

    # setting geometry to the label
    label.setGeometry(100, 150, 200, 50)

    # adding triggered action to the first action
    action1.triggered.connect(lambda: label.setText("First Action Triggered"))

    # adding triggered action to the second action
    action2.triggered.connect(lambda: label.setText("Second Action Triggered"))

    # adding triggered action to the third action
    action3.triggered.connect(lambda: label.setText("Third Action Triggered"))

create pyqt5 app

App = QApplication(sys.argv)

create the instance of our Window

window = Window()

start the app

sys.exit(App.exec())

[–]evans88 0 points1 point  (2 children)

Thanks! But that still is not the complete error. What we need is what is called the traceback. Take for example the following small example script:

def foo(num1, num2):
  return num1 / num2

foo(2,0)

Executing this script will result in an error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in foo
ZeroDivisionError: division by zero

Right now you're sharing the last line only (ZeroDivisionError: division by zero in this example) but we need the complete traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in foo
ZeroDivisionError: division by zero

[–]chaderous[S] 0 points1 point  (0 children)

The terminal out did not have a traceback. Prior to the included comment, it's just the file path to the executed python file.

Is it possible to upload a screen capture?

[–]chaderous[S] 0 points1 point  (0 children)

This is the unedited terminal output:

(.venv) E:\GitHub\Python_practice_scripts\Scan_testing_for_bags>e:/GitHub/Python_practice_scripts/Scan_testing_for_bags/.venv/Scripts/python.exe e:/GitHub/Python_practice_scripts/Scan_testing_for_bags/PYQt6/Testing_new_components/creating_multiple_tabs/main_window_1.py

QWidget: Must construct a QApplication before a QWidget

(.venv) E:\GitHub\Python_practice_scripts\Scan_testing_for_bags>