下記のソースコードで、2つのメニュー画面(最初のメニュー画面はInitGUI()で、2番目のメニュー画面はNextMenu()で表示)を用意して、最初のメニュー画面で、button1がクリックされて、welcome()関数に飛び、その中で、quitbutton2が押された時に、最初のメニュー画面(InitGUI()で表示させた画面)に戻るようにしたいのですが、この場合に、どのような関数を使ったらよいのかご教示頂きたく。下記のソースコード中のback()で、BASIC等の言語で使うGOTO文みたいな命令を使いたのですが、Pythonにはそのような命令が無いので、どうしたらよいのか、分からなく。 Pythonに関する初心者的質問ですみません。
Python3
1import sys, openpyxl, json, random 2 3from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QPushButton, QAction, QApplication, QMessageBox, QLabel, QLineEdit 4from PyQt5.QtGui import QFont, QIcon, QPixmap 5from PyQt5.QtCore import QCoreApplication, pyqtSlot 6 7class StartMenu(QWidget): 8 def __init__(self): 9 super().__init__() 10 11 self.title = "Hello" 12 13 self.initGUI() 14 15 self.resize(500, 300) 16 self.move(100, 0) 17 self.show() 18 19 def initGUI(self): 20 self.setWindowTitle(self.title) 21 22 self.button1 = QPushButton('Welcome', self) 23 self.button1.move(230, 120) 24 self.button1.clicked.connect(self.welcome) 25 26 self.quitbutton1 = QPushButton('exit', self) 27 self.quitbutton1.move (230, 200) 28 self.quitbutton1.clicked.connect(QCoreApplication.instance().quit) 29 30 self.button2 = QPushButton('Hello', self) 31 self.button2.move (230, 120) 32 self.button2.hide() 33 34 self.quitbutton2 = QPushButton('quit', self) 35 self.quitbutton2.move (230, 200) 36 self.quitbutton2.hide() 37 38 def welcome(self): 39 self.All_Erase1() 40 self.NextMenu() 41 42 def All_Erase1(self): 43 self.button1.hide() 44 self.quitbutton1.hide() 45 46 def All_Erase2(self): 47 self.button2.hide() 48 self.quitbutton2.hide() 49 50 def NextMenu(self): 51 self.button2.show() 52 self.button2.clicked.connect(self.hello) 53 54 self.quitbutton2.show() 55 #self.quitbutton2.clicked.connect(QCoreApplication.instance().quit) 56 self.quitbutton2.clicked.connect(self.back) 57 58 def hello(self): 59 print("hello") 60 self.All_Erase2() 61 62 def back(self): 63 self.All_Erase2() 64 #ここにどんな関数を使ったらinitGUIで表示させた最初のメニュー画面に戻れるのでしょうか 65 66if __name__ == '__main__': 67 app = QApplication(sys.argv) 68 ex1 = StartMenu() 69 70 sys.exit(app.exec_()) 71
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/20 05:58