如何在同一班上调用第二个窗口?
我该如何调用同一类中的两个窗口之一。最重要的是:首先打开一个对话框窗口,然后登录_CLICKECKECT函数(未添加到REPP代码中),当您单击对话框窗口中的按钮时,login_clicked()函数会触发,在login_clicked()函数的末尾,第二个窗口已经打开,并且对话框窗口被.destroy()
PS破坏,如果您建议创建2个单独的类第二个窗口,如果您告诉我,我会很高兴。
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QWidget, QApplication
import sys
class Ui_Dialog(object):
def main(self, SecondWin):
SecondWin.setObjectName("SecWin")
SecondWin.setFixedSize(530, 416)
SecondWin.setWindowTitle("HMessage")
app = QtWidgets.QApplication(sys.argv)
SecondWin = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.main(SecondWin)
SecondWin.show()
app.exec()
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.setFixedSize(400, 265)
QtCore.QMetaObject.connectSlotsByName(Dialog)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
app.exec_()
how can I call one of two windows that are both in the same class. The bottom line is this: first a Dialog window opens, then the login_clicked function works(it was not added to the repl code), and when you click on the button in the Dialog window, the login_clicked() function is triggered,and at the end of the login_clicked() function, the SecondWin window already opens, and the Dialog window is destroyed with .destroy()
P.S if you advise creating 2 separate classes, then I also tried, but I can't link them and call the SecondWin window, I'll be glad if you tell me.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QWidget, QApplication
import sys
class Ui_Dialog(object):
def main(self, SecondWin):
SecondWin.setObjectName("SecWin")
SecondWin.setFixedSize(530, 416)
SecondWin.setWindowTitle("HMessage")
app = QtWidgets.QApplication(sys.argv)
SecondWin = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.main(SecondWin)
SecondWin.show()
app.exec()
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.setFixedSize(400, 265)
QtCore.QMetaObject.connectSlotsByName(Dialog)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
app.exec_()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在工作中使用的东西也有类似的情况,我只在第一个登录窗口上使用.exec_(),当关闭该窗口时,我返回登录是否成功。然后,如果登录工作,我在主窗口上使用.show()。
在此示例中,我的两个窗口都在单独的类中,第一个窗口将保持主导,直到关闭该登录窗口为止。然后,它将显示主窗口,或者仅根据我在loginwindow()的self.accept()方法中返回的变量来结束程序。
您确实应该分别为Windows上课,因为它可以使事情更容易跟踪,并且每个窗口的范围都更容易遵循。
这是在类中初始化QDialog的一个示例。
I have a similar situation with something I use at work and I just use .exec_() on the first login window and when that window is closed, I return whether the login was successful or not. Then I use .show() on the main window if the login worked.
In this example both my windows are in separate classes and the first window will hold the main from executing until that login window is closed. Then it will either show the main window or it will just end the program based on what variable I returned in my LoginWindow() 's self.accept() method.
You really should be making classes for the windows individually because it makes things much easier to keep track of and the scope of each window is easier to follow that way.
Here's an example of initializing a QDialog within the class.