Python GUI制作后退按钮

2024-06-25 23:15:40 发布

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

class dashboard(Frame):
    def __init__(self, master):
        super(dashboard, self).__init__(master)
        self.grid()
        self.main_menu()

    def main_menu(self):
        for button in self.student_page_buttons: 
            button.grid_forget()
        #student dashboard button
        bttn1 = Button(self, text = "Student",
                       command=self.student, height = 2, width= 15)
        bttn1.grid()

        #teacher dashboard button
        bttn2 = Button(self, text = "Teacher",
                       command=self.teacher, height = 2, width= 15)
        bttn2.grid()

        #exit button
        bttn3 = Button(self, text = "Exit",
               command=self.exit, height = 2, width= 15)
        bttn3.grid()

        self.main_page_buttons = bttn1, bttn2, bttn3  # Save button widgets.

    def student(self):
        for button in self.main_page_buttons:  # Hide the main page Buttons.
            button.grid_forget()

        #view highscores button
        bttn1 = Button(self, text = "Highscores",
                       command=self.view_scores, height = 2, width= 15)
        bttn1.grid()

        #print score button
        bttn2 = Button(self, text = "Save Score",
                       command=self.save_score, height = 2, width= 15)
        bttn2.grid()

        #back button
        bttn3 = Button(self, text = "Back",
               command=self.main_menu, height = 2, width= 15)
        bttn3.grid()

        self.student_page_buttons = bttn1, bttn2, bttn3  # Save button widgets.

我试着做一个后退按钮有一段时间了,现在还不明白为什么这个后退按钮不起作用,如果有人有一些建议或有用的链接,这将是伟大的。我基本上希望能够访问学生部分以及返回主菜单与主菜单按钮,而不是学生和主菜单相结合。你知道吗


Tags: textselfmainpagebuttonwidthstudentcommand