私が取り組んできた閉じて、これは私がこれまで持っているものです:私はクラスのメインウィンドウのMWを作成しようとするとPyQt4ウィンドウがPyQt4アプリケーションに自動的に
import sys
from PyQt4 import QtGui, QtCore
class PasswordPrompt(QtGui.QWidget):
def __init__(self):
super(PasswordPrompt, self).__init__()
self.initUi()
def initUi(self):
self.setFixedSize(500, 75)
self.setWindowTitle('Please enter the password...')
self.prompt = QtGui.QLineEdit(self)
self.btn = QtGui.QPushButton('Enter', self)
self.btn.clicked.connect(self.btnClicked)
self.hbox = QtGui.QHBoxLayout()
self.hbox.addWidget(self.prompt)
self.hbox.addWidget(self.btn)
self.vbox = QtGui.QVBoxLayout()
self.vbox.addLayout(self.hbox)
self.vbox2 = QtGui.QVBoxLayout()
self.vbox2.addSpacing(300)
self.hbox2 = QtGui.QHBoxLayout()
self.hbox2.addSpacing(150)
self.vbox2.addLayout(self.hbox2)
self.vbox.addLayout(self.vbox2)
self.setLayout(self.vbox)
self.center()
self.show()
def btnClicked(self):
pw = self.prompt.text()
if pw == "password":
print("Permission granted!")
self.close()
mw = MainWindow()
else:
print("Permissed denied!")
self.prompt.clear()
self.warningText = QtGui.QLabel('That is the wrong password!', self)
self.hbox2.addWidget(self.warningText)
def center(self):
qr = self.frameGeometry()
cp = QtGui.QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
class MainWindow(QtGui.QWidget):
def __init__(self):
super(MainWindow, self).__init__()
self.initUi()
def initUi(self):
self.setWindowTitle('Main Menu')
self.setFixedSize(1000, 800)
self.show()
def main():
application = QtGui.QApplication(sys.argv)
p = PasswordPrompt()
sys.exit(application.exec())
if __name__=='__main__':
main()
私の問題が来ます。なんらかの理由で、MainWindow.initui()を実行してからすぐに終了します。私はそれがmain()関数とQApplicationオブジェクトと関係があると仮定します。複数のウィンドウをコーディングしてこれを回避する最良の方法は何ですか?私はもともとウィンドウごとにクラスを作成しようとしていました:passwordPrompt、MainMenuなど、新しいウィンドウを読み込むために各クラスのインスタンスをインスタンス化しましたが、それは動作していないことがわかります。
こんにちは@WewLad、あなたは答えの1つを見つけるのに役立ちましたか?あなたの問題が解決されることを願っています:-) –