2017-11-13 10 views
0

GUIで作業するのは非常に新しいので、複数のフレームをリンクしてそのフレームに移動するためのボタンを押すことができるかどうか、Python - 複数のフレームをリンクする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() 
+1

調査は行っていますか?これに類似した多くの質問がStackoverflowにあります。 –

答えて

1

あなたは、あなたがネストされたトップレベルを持っています入れ子になったクラスと新しい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() 
関連する問題