用PyQt5中的按钮打开其他窗口

2024-04-18 21:57:35 发布

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

我想打开另一个窗口,当用户使用按钮! 我用qt5设计器实现用户界面。 这就是我的主窗口代码:

#!/usr/bin/python3
import sys
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5 import QtGui,QtCore
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QMainWindow, QDialog
from PyQt5.QtCore import Qt
from sas import Ui_MainWindow
from langs import Ui_MainWindow2

class langse(QDialog, Ui_MainWindow2):
    def __init__(self, parent=None):
        super(langse, self).__init__(parent)
        self.setupUi(self)


class myprog(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(myprog, self).__init__(parent)
        self.setupUi(self)

        self.radioButton_2.toggled.connect(lambda:self.enableChoose())
        self.pushButton_5.clicked.connect(self.onchbtn)
        self.radioButton.toggled.connect(lambda:self.disableChoose())
    def enableChoose(self):
        self.pushButton_5.setEnabled(True)

    def disableChoose(self):
        self.pushButton_5.setEnabled(False)

    def onchbtn(self):
        widget = langse()
        widget.exec_()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = myprog()
    window.show()
    sys.exit(app.exec_())

但当我使用“选择”按钮时,我会看到以下错误:

^{pr2}$

我需要为新窗口使用一些函数,所以我这么做了,但我听说QDialog可以做(运行另一个窗口),但你不能为对象使用函数和代码。。。 谢谢。在


Tags: fromimportselfuiinitdefconnectsys