如何使按钮返回到pyqt5上的上一个窗口?

2024-05-01 22:01:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我想回到我被点击的前一个窗口

我做两扇窗户。第一个是Main_Menu.py,第二个是Current_Stalls.py我想通过单击按钮Current Stalls从Main_菜单转换到Current_Stalls。然后在进入当前摊位窗口后,我把按钮名调回主页,以便返回主菜单页。但是在我编写代码之后,它无法导入其他模块

主菜单程序

from PyQt5 import QtCore, QtGui, QtWidgets
from Current_Stalls import Ui_OtherWindow2
class Ui_MainWindow(object):
    def openWindow2(self):
        self.window = QtWidgets.QMainWindow()
        self.ui = Ui_AnotherWindow()
        self.ui.setupUi(self.window)
        MainWindow.hide()
        self.window.show()

        self.current_stall = QtWidgets.QPushButton(self.centralwidget)
        self.current_stall.setGeometry(QtCore.QRect(280, 200, 231, 41))
        self.current_stall.setObjectName("current_stall")
        self.current_stall.clicked.connect(self.openWindow2) 

当前暂停程序

from PyQt5 import QtCore, QtGui, QtWidgets
from Main_Menu import Ui_MainWindow
class Ui_AnotherWindow(object):
    def openWindow(self):
        self.window = QtWidgets.QAnotherWindow()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self.window)
        AnotherWindow.hide()
        self.window.show()   

        self.backHome = QtWidgets.QPushButton(self.centralwidget)
        self.backHome.setGeometry(QtCore.QRect(600, 20, 161, 41))
        self.backHome.setObjectName("backHome")
        self.backHome.clicked.connect(self.openWindow)

Tags: fromimportselfuimaincurrentwindowqtcore