A
A
arama922018-04-20 21:22:02
Python
arama92, 2018-04-20 21:22:02

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

1 answer(s)
N
Nikita Shoshin, 2018-04-21
@arama92

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()

I'm not sure, though, that it's worth doing this, but in your case it should help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question