Python-GUI链接多个框架

Python-GUI链接多个框架,python,user-interface,tkinter,Python,User Interface,Tkinter,非常新的GUI的工作,所以我想知道是否有人可以给我一些指导,如何链接多个帧,以便您可以按下按钮转到该帧 如果有人有想法或建议,那就太好了 from tkinter import * class main(Frame): def __init__(self, master=None): super(main, self).__init__(master) self.grid() self.pack() def buttons_dash

非常新的GUI的工作,所以我想知道是否有人可以给我一些指导,如何链接多个帧,以便您可以按下按钮转到该帧

如果有人有想法或建议,那就太好了

from tkinter import *

class main(Frame):
   def __init__(self, master=None):
       super(main, self).__init__(master)    
       self.grid()
       self.pack()
   def buttons_dash():
      # create first button
       self.bttn1_dash = Button(self, text = "Student Login",)
       self.bttn1_dash.grid()
       self.bttn1_dash.config(height=3, width=30)

       # create second button
       self.bttn2_dash = Button(self)
       self.bttn2_dash.grid()   
       self.bttn2_dash.configure(text = "Staff Login")
       self.bttn2_dash.config(height=3, width=30)

       # create third button
       self.bttn3_dash = Button(self)
       self.bttn3_dash.grid()
       self.bttn3_dash["text"] = "Exit"
       self.bttn3_dash.config(height=3, width=30)
       self.bttn3_dash = Button(self, text= "Exit")

class student_dashboard(Frame):
      def __init__(self, master=None):
       super(main, self).__init__(master)    
       self.grid()
       self.pack()
      def buttons_student():
       #create first button
       self.bttn1_student = Button(self, text = "View Highscores")
       self.bttn1_student.grid()
       self.bttn1_student.config(height=3, width=30)

       # create second button
       self.bttn2_student = Button(self)
       self.bttn2_student.grid()    
       self.bttn2_student.configure(text = "Save Score")
       self.bttn2_student.config(height=3, width=30)

# main
root = Tk()
root.title("Dashboard")
app = main(root)
root.mainloop()

您可以使用调用包含嵌套类和新tkinter框架的函数的命令在主类中创建一个按钮,然后您将拥有一个嵌套的顶层

import tkinter as tk
class main:
    def __init__(self, root1):
        self.root1=root1
        self.frame1=tk.Frame(root1)
        self.button_spawn_top=tk.Button(text="spawn_frame",
        command=self.new_window)
        self.button_spawn_top.grid(row=0,column=0)
        self.frame1.grid(row=0,column=0)
    def new_window(self):
        class NewWindow:
            def __init__(self, root2):
                self.root2=root2
                self.frame2=tk.Frame(root2)
                self.label2=tk.Label(text='new_window')
                self.label2.grid(row=0,column=0)
                self.frame2.grid(row=0,column=0)
        root2=tk.Toplevel()
        app2=NewWindow(root2)
root1=tk.Tk()
app1=main(root1)
root1.mainloop()

你做过什么调查吗?在Stackoverflow上有许多类似的问题。