The problem is simple: Main is created with a limited scope, so a moment later it will be eliminated, so the window is seen in a single moment.
The objective could be rewritten as: when the button is pressed then the other window must be shown, for the user it is indifferent if it is created before the window or not but only shown.
class Login(QMainWindow):
def __init__(self):
super().__init__()
self.other_window = Main()
self.setGeometry(750, 350, 400, 225)
self.setWindowTitle('Login')
#stuff right here
self.tombol = QPushButton('Login', self)
self.tombol.setGeometry(225, 150, 101, 23)
self.tombol.clicked.connect(self.other_window.show)
self.show()
class Main(QMainWindow):
def __init__(self):
super().__init__()
self.setGeometry(750, 350, 400, 150)
self.setWindowTitle('Hasil Pilkada')
#stuff right here too
# self.show()
Another way where if the window is created and shown:
class Login(QMainWindow):
def __init__(self):
super().__init__()
self.setGeometry(750, 350, 400, 225)
self.setWindowTitle('Login')
#stuff right here
self.tombol = QPushButton('Login', self)
self.tombol.setGeometry(225, 150, 101, 23)
self.tombol.clicked.connect(self.handle_clicked)
self.show()
def handle_clicked(self):
if not hasattr(self, "other_window"):
self.other_window = Main()
self.other_window.show()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…