当用户使用pushButton时,我想打开另一个窗口! 我使用qt5设计器用于UI。 这是我的主要窗口代码:
#!/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_())
但是当我使用“选择”按钮时,我会看到此错误:
Traceback (most recent call last):
File "./main.py", line 35, in onchbtn
widget = langse()
File "./main.py", line 14, in __init__
self.setupUi(self)
File "/home/amirrezaw/p/GTranslate/langs.py", line 336, in setupUi
MainWindow.setCentralWidget(self.centralwidget)
AttributeError: 'langse' object has no attribute 'setCentralWidget'
我需要为新窗口使用一些功能,所以我做了,但我听说QDialog可以做到(运行另一个窗口),但你不能使用函数和代码对象... 感谢。