2017-10-15 68 views
0

我是Python的初學者,需要Tkinter的幫助。Tkinter - 只能查看最後一頁

下面的程序打開一個只顯示最後一頁的窗口(頁面名稱爲PageOne)。我無法查看第一頁(起始頁代碼

LARGE_FONT = ("Verdana", 12) 
import tkinter as tk 
from PIL import ImageTk, Image 

class Food(tk.Tk): 
    def __init__(self,*args,**kwargs): 
     tk.Tk.__init__(self,*args,**kwargs) 
     container = tk.Frame(self) 
     container.pack(side="top", fill="both",expand = True) 
     container.grid_rowconfigure(0, weight=1) 
     container.grid_columnconfigure(0, weight=1) 
     self.frames = {} 

     for F in (StartPage, PageOne): 
      frame = F(container,self) 
      self.frames[F] = frame 
      frame.grid(row=0,column=0,sticky="nsew") 
     self.show_frame(StartPage) 
    def show_frame(self,cont): 
     frame = self.frames[cont] 
     frame.tkraise 


class StartPage(tk.Frame): 
    def __init__(self,parent,controller): 
     tk.Frame.__init__(self,parent) 
     label = tk.Label(self,text = "PortFoodlio", font = LARGE_FONT) 
     label.pack(pady = 100, padx = 100) 
     button1 = tk.Button(self, text = "Let's get started!", 
         command = lambda: 
         controller.show_frame(PageOne)) 
    button1.pack() 

class PageOne(tk.Frame): 
    def __init__(self,parent,controller): 
     tk.Frame.__init__(self,parent) 
     label = tk.Label(self,text = "Ingredients", font = LARGE_FONT) 
     label.pack(pady = 100, padx = 100) 
     button2 = tk.Button(self, text = "Back to Home", 
         command= lambda: 
         controller.show_frame(StartPage)) 
    button2.pack()   


app = Food() 
app.mainloop() 
+3

您需要_call_''中的方法show_frame'你tkraise'忘了圓括號。投票關閉爲主題 - 錯字 – Lafexlos

回答

0

錯誤就行:tk.raise 它應該是:tk.raise()

+0

請使用您的問題的編輯鏈接添加額外的信息。後回答按鈕應該只用於完整答案的問題。 - [來自評論](/評論/低質帖/ 18875527) – pirho