Я понимаю, что этот вопрос задавался много раз, но я не могу применить его к своему коду.В моем коде у меня есть переменная с именем username в классе Ui_MainWindow, которую я хочу использовать в классе.
from viewAllRooms import Ui_ViewAllRooms
from teacher_menu import Ui_Menu
from viewAllRooms import Ui_ViewAllRooms
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Menu(QtWidgets.QMainWindow, Ui_Menu):
def __init__(self, parent=None):
super(Ui_Menu, self).__init__(parent)
self.setupUi(self)
self.viewAll = Ui_ViewAllRooms()
self.viewall_button.clicked.connect(self.viewAll.show)
self.viewall_button.clicked.connect(self.hide)
class Ui_ViewAllRooms(QtWidgets.QMainWindow, Ui_ViewAllRooms):
def __init__(self, parent=None):
super(Ui_ViewAllRooms, self).__init__(parent)
self.setupUi(self)
self.book_Button.clicked.connect(self.book_clicked)
@QtCore.pyqtSlot()
def book_clicked(self):
self._checked_items = []
self.dialogBook.show()
self.dialogBook.yes_button.clicked.connect(self.addBooking)
def addBooking(self):
now = QDate.currentDate()
now1 = now.toString(Qt.DefaultLocaleLongDate)
#I want to use the username here#
class Ui_MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def loginCheck(self):
username = self.user_enter.text()
#I have code here which connects to database to check username details
#If the username is found in database then:
self.hide()
self.teacherMenu = Ui_Menu()
self.teacherMenu.show()
def __init__(self, parent=None):
super(Ui_MainWindow, self).__init__(parent)
self.setupUi(self)
self.loginCheck()
self.login_button.clicked.connect(self.loginCheck)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = Ui_MainWindow()
w.show()
sys.exit(app.exec_())
Если вы ответите, не могли бы вы объяснить, как вы это сделали, чтобы я мог понять.
Спасибо