Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. TypeError : 'module' object is not callable on MainWindow
Forum Updated to NodeBB v4.3 + New Features

TypeError : 'module' object is not callable on MainWindow

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 398 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sighroos
    wrote on 30 Nov 2024, 22:14 last edited by
    #1

    I've separated everything into their own files, its just easier for me to track this way. Anyway, I have a similar version of this code that is using a DockWidget. I wanted to see if I could accomplish something similar without the DockWidget as its kind of a pain to work with. Anyway, I thought I had the code pretty much the same, but for some reason the script is getting caught up on the 8th line in the overlay.py file (window = MainWindow()).

    Not sure why its having issues with this now, so I thought I'd run to a forum and get some extra eyes on what is hopefully a simple oversight. Sorry if the Qt code seems messy or incorrect, learning this library for my final project.

    # overlay.py
    
    import MainWindow
    from PySide6.QtCore import Qt, QSize
    from PySide6.QtGui import QPixmap, QImage
    from PySide6.QtWidgets import QApplication, QDockWidget, QWidget, QLabel, QVBoxLayout
    
    app = QApplication([])
    window = MainWindow()
    
    window.show()
    app.exec()
    
    

    The following is the MainWindow code:

    # MainWindow.py
    from PySide6.QtCore import QSize, Qt
    from PySide6.QtWidgets import QApplication, QMainWindow, QDockWidget, QWidget, QLabel, QVBoxLayout
    from PySide6.QtGui import QPixmap
    import App
    
    class MainWindow(QMainWindow):
        def __init__(self):
            super().__init__()
            
            self.app = App()
            self.setWindowTitle("Nagata")
            
            # setGeometry
            screen_Bounds = QApplication.primaryScreen().geometry()
            window_width = 900
            window_height = 800
            x = screen_Bounds.width() - window_width
            y = screen_Bounds.height() - window_height - screen_Bounds.y()
            
            self.setGeometry(x ,y, window_width, window_height)
                    
            # Transparency flags
            self.setWindowFlags(Qt.FramelessWindowHint)
            self.setAttribute(Qt.WA_TranslucentBackground)
            
            self.setCentralWidget(self.app)
    

    The final file, App.py (called in MainWindow)

    import sys
    from PySide6.QtWidgets import *
    from PySide6.QtCore import Qt, QSize
    from PySide6.QtGui import QPixmap
    
    class App(QWidget):
        def __init__(self):
            super().__init__()
    
            self.initUI()
    
        def initUI(self):
            self.main_Layout = QVBoxLayout()
            self.tray_Widget = QWidget()
            self.tray_Label = QLabel()
            self.tray_Logo = "file_path"
            self.pixmap = QPixmap(self.tray_Logo)
    
            if self.pixmap.isNull():
                print(f"Failed to load image from {self.tray_Logo}")
    
            else:
                self.tray_Label.setPixmap(self.pixmap)
                self.tray_Label.setAlignment(Qt.AlignLeft)
    
            # Init tray_Widget     
            self.tray_Widget.setAlignment(Qt.AlignLeft | Qt.AlignCenter)
            self.tray_Widget.addWidget(self.tray_Label)
            
            self.main_Layout.addWidget(self.tray_Widget)
    
            self.setLayout(self.main_Layout)
    

    Additional apologies if this is formatted terribly. FIrst time coming to these forums. Figured you lot might be more tolerable/understanding that some other forums... that wont be named... lol. Please if you have any ways in which youd fix the formatting let me know. I look forward to my journey here and to any aid I may be able to gather.

    P 1 Reply Last reply 30 Nov 2024, 23:45
    0
    • S Sighroos
      30 Nov 2024, 22:14

      I've separated everything into their own files, its just easier for me to track this way. Anyway, I have a similar version of this code that is using a DockWidget. I wanted to see if I could accomplish something similar without the DockWidget as its kind of a pain to work with. Anyway, I thought I had the code pretty much the same, but for some reason the script is getting caught up on the 8th line in the overlay.py file (window = MainWindow()).

      Not sure why its having issues with this now, so I thought I'd run to a forum and get some extra eyes on what is hopefully a simple oversight. Sorry if the Qt code seems messy or incorrect, learning this library for my final project.

      # overlay.py
      
      import MainWindow
      from PySide6.QtCore import Qt, QSize
      from PySide6.QtGui import QPixmap, QImage
      from PySide6.QtWidgets import QApplication, QDockWidget, QWidget, QLabel, QVBoxLayout
      
      app = QApplication([])
      window = MainWindow()
      
      window.show()
      app.exec()
      
      

      The following is the MainWindow code:

      # MainWindow.py
      from PySide6.QtCore import QSize, Qt
      from PySide6.QtWidgets import QApplication, QMainWindow, QDockWidget, QWidget, QLabel, QVBoxLayout
      from PySide6.QtGui import QPixmap
      import App
      
      class MainWindow(QMainWindow):
          def __init__(self):
              super().__init__()
              
              self.app = App()
              self.setWindowTitle("Nagata")
              
              # setGeometry
              screen_Bounds = QApplication.primaryScreen().geometry()
              window_width = 900
              window_height = 800
              x = screen_Bounds.width() - window_width
              y = screen_Bounds.height() - window_height - screen_Bounds.y()
              
              self.setGeometry(x ,y, window_width, window_height)
                      
              # Transparency flags
              self.setWindowFlags(Qt.FramelessWindowHint)
              self.setAttribute(Qt.WA_TranslucentBackground)
              
              self.setCentralWidget(self.app)
      

      The final file, App.py (called in MainWindow)

      import sys
      from PySide6.QtWidgets import *
      from PySide6.QtCore import Qt, QSize
      from PySide6.QtGui import QPixmap
      
      class App(QWidget):
          def __init__(self):
              super().__init__()
      
              self.initUI()
      
          def initUI(self):
              self.main_Layout = QVBoxLayout()
              self.tray_Widget = QWidget()
              self.tray_Label = QLabel()
              self.tray_Logo = "file_path"
              self.pixmap = QPixmap(self.tray_Logo)
      
              if self.pixmap.isNull():
                  print(f"Failed to load image from {self.tray_Logo}")
      
              else:
                  self.tray_Label.setPixmap(self.pixmap)
                  self.tray_Label.setAlignment(Qt.AlignLeft)
      
              # Init tray_Widget     
              self.tray_Widget.setAlignment(Qt.AlignLeft | Qt.AlignCenter)
              self.tray_Widget.addWidget(self.tray_Label)
              
              self.main_Layout.addWidget(self.tray_Widget)
      
              self.setLayout(self.main_Layout)
      

      Additional apologies if this is formatted terribly. FIrst time coming to these forums. Figured you lot might be more tolerable/understanding that some other forums... that wont be named... lol. Please if you have any ways in which youd fix the formatting let me know. I look forward to my journey here and to any aid I may be able to gather.

      P Offline
      P Offline
      Pl45m4
      wrote on 30 Nov 2024, 23:45 last edited by Pl45m4
      #2

      @Sighroos

      Hi and welcome to the forum :)

      It's indeed a rookie Python mistake :)

      Change to either

      from MainWindow import MainWindow
      

      OR

      window = MainWindow.MainWindow()
      

      Then it should work.

      @Sighroos said in TypeError : 'module' object is not callable on MainWindow:

      some other forums... that wont be named... lol.

      we all know this place :D


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      S 1 Reply Last reply 1 Dec 2024, 00:03
      2
      • P Pl45m4
        30 Nov 2024, 23:45

        @Sighroos

        Hi and welcome to the forum :)

        It's indeed a rookie Python mistake :)

        Change to either

        from MainWindow import MainWindow
        

        OR

        window = MainWindow.MainWindow()
        

        Then it should work.

        @Sighroos said in TypeError : 'module' object is not callable on MainWindow:

        some other forums... that wont be named... lol.

        we all know this place :D

        S Offline
        S Offline
        Sighroos
        wrote on 1 Dec 2024, 00:03 last edited by
        #3

        @Pl45m4 Thank you, of course its as simple as that -.- I was so confused, thinking maybe I had erased a needed line somewhere and didnt even think about looking at the import statements... It absolutely solved my issue, thanks again!

        1 Reply Last reply
        0
        • S Sighroos has marked this topic as solved on 1 Dec 2024, 00:04

        1/3

        30 Nov 2024, 22:14

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved