You’re showing window
, not Main()
.
Take window.show()
out of your __init__
method
Then, when you create your dialog, that’s what you show.
myDlg = Main()
myDlg.show()
[Edit]
Ok, now that the dialog is showing (or at least it does on my machine with the above change), there’s one thing that you should really fix, IMO
Don’t use global variables (like main_window
in your example). That means the __init__
for Main
has to take a second argument like this def __init__(self, parent):
Also, passing main_window
to the super init already sets the parent of your dialog, so you don’t need self.setParent(main_window)
So then, when you make your dialog, you pass its parent to it.
Oh yeah, and since you’re calling self.window
in your close method, you have to make sure to store the window somewhere.
This is what the dialog and startup looks like after the changes I suggest.
class Main(QDialog):
def __init__(self, parent):
super(Main, self).__init__(parent)
ui_file = QFile("T:/utils/VAT/VATUI.ui")
ui_file.open(QFile.ReadOnly)
self.window = QUiLoader().load(ui_file, parent=self)
ui_file.close()
btn = self.window.findChild(QPushButton, 'exportas_button')
btn.clicked.connect(self.closeEvent)
def closeEvent(self, event):
""" on close, this closes the ui """
super(Main, self).closeEvent(event)
self.window.close()
main_window = get_main_window()
md = Main(main_window)
md.show()
There are still some other issues (like self.window
not being in a layout, so it doesn’t show properly), but that’s for your next question!