A
A
arama922018-05-13 23:43:08
Python
arama92, 2018-05-13 23:43:08

How to import a class from another file?

How to import a class from another file in
ZZZ.py folder

from PyQt5.QtWidgets import *
from PyQt5.uic import loadUi
from PyQt5 import QtCore
import sys
import Case_next.Start_1 # возможно правильно
class Case(QMainWindow):
    def __init__(self):
        super(Case, self).__init__()
        self.case()
    def case(self):
        loadUi("Case.ui", self)
        self.pb_1.clicked.connect(self.start_1)
    def start_1(self):
        self.go = Case_next.Start_1.Go() # Error 
if __name__ == '__main__':
    app = QApplication(sys.argv)
    case = Case()
    case.show()
    sys.exit(app.exec_())

Case_next/Start_1.py
from PyQt5.QtWidgets import *
from PyQt5.uic import loadUi
from  PyQt5 import QtCore
import sys

class Go(QMainWindow):
    def __init__(self):
        super(Go, self).__init__ 
        loadUi("form/serv.ui", self)
        self.pb.clicked.connect(self.pprint)
        self.pb.setShortcut("return")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2018-05-14
@vasilek-nik

In the Case_next folder, create an empty __init__.py file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question