TypeError : 'module' object is not callable on MainWindow
-
wrote on 30 Nov 2024, 22:14 last edited by
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.
-
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.
wrote on 30 Nov 2024, 23:45 last edited by Pl45m4Hi 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
-
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
wrote on 1 Dec 2024, 00:03 last edited by@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/3