Answer the question
In order to leave comments, you need to log in
How to call another class?
There are 2 classes. Each of them has a form. It is necessary to open a window of another class on command. How to do it ?
import os
import sys
from PyQt5.QtWidgets import *
from PyQt5.uic import loadUi
from PyQt5.QtGui import *
from pytube import YouTube
import threading
class Menu(QMainWindow):
def __init__(self):
super(Menu, self).__init__()
loadUi("un1.ui", self)
self.pb1.clicked.connect(self.next)
def next(self):
# Не знаю как написать тут вызов
# Next().show() не работает
class Next(QMainWindow):
def __init__(self):
super(Next, self).__init__()
loadUi("un2.ui", self)
self.pb2.clicked.connect(self.pp)
def pp(self):
print(1)
if __name__ == '__main__':
app = QApplication(sys.argv)
mainWindow = Menu()
mainWindow.show()
sys.exit(app.exec_())
Answer the question
In order to leave comments, you need to log in
To call a method of another class, you need an instance of that class. Decision:
def __init__(self):
super(Menu, self).__init__()
loadUi("un1.ui", self)
self.pb1.clicked.connect(self.next)
nextWindow = Next()
def next(self):
nextWindow.show()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question