看板 Python 關於我們 聯絡資訊
: 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, PageThree): : 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, root): : super().__init__(parent) : butt3 = tk.Button(self, text="Page3", command = lambda: : root.show_frame(PageThree)) : butt3.place(x=100, y=400, width=150, height=80) : butt4 = tk.Button(self, text="Plot", command = on_Plot) : butt4.place(x=300, y=400, width=150, height=80) : class PageThree(tk.Frame): : def __init__(self, parent, root): : super().__init__(parent) : button1 = tk.Button(self, text="Home", command=lambda: : root.show_frame(StartPage)).pack() : root = Application() : root.mainloop() 如果只是要做到特效的話其實做法很多 就算你是畫在root上 只要在切到frame3上面的時候 幫label換張圖也行 https://stackoverflow.com/questions/39580739/python-tkinter-label-in-frame 我通常會用的做法就是畫在frame1上面 你用的label其實應該是要放在frame1 這樣當frame3 show出的時候你就看不到了 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.194.181.152 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1536987134.A.441.html
caesar0929: 謝謝 因為我第三張有另外做一些事情 換圖的話可能會比 09/15 23:15
caesar0929: 較麻煩 我其實也是想只畫在frame1上就好了 但我不知道 09/15 23:15
caesar0929: 關鍵字是什麼QQ 還請大大指點迷津~~謝謝 09/15 23:15
caesar0929: La = tk.Label(root, text="abc", image=img1, bg='gr 09/15 23:19
caesar0929: 應該是上面這行需要修改 但我不知道root要改成什麼 09/15 23:20
caesar0929: 才會只畫在frame1上面~~ 09/15 23:20
我沒寫過這個 但感覺語法應該是長這樣 class StartPage(tk.Frame): def __init__(self, parent, root): super().__init__(parent) butt3 = tk.Button(self, text="Page3", command = lambda: root.show_frame(PageThree)) butt3.place(x=100, y=400, width=150, height=80) butt4 = tk.Button(self, text="Plot", command = on_Plot) butt4.place(x=300, y=400, width=150, height=80) //============on_Plot() CODE=================== img1 = ImageTk.PhotoImage(file='Hey.jpg') //La = tk.Label(root, text="abc", image=img1, bg='gray') La = tk.Label(self, text="abc", image=img1, bg='gray') La.place(x=200, y=150, width=100, height=100) La.update_idletasks() //===============on_Plot() CODE================= ※ 編輯: MOONY135 (123.194.181.152), 09/16/2018 09:31:00