Re: [問題] Plt只顯示在某個frame而不是Tk全部frame
: 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
推
09/15 23:15,
5年前
, 1F
09/15 23:15, 1F
→
09/15 23:15,
5年前
, 2F
09/15 23:15, 2F
→
09/15 23:15,
5年前
, 3F
09/15 23:15, 3F
推
09/15 23:19,
5年前
, 4F
09/15 23:19, 4F
→
09/15 23:20,
5年前
, 5F
09/15 23:20, 5F
→
09/15 23:20,
5年前
, 6F
09/15 23:20, 6F
我沒寫過這個 但感覺語法應該是長這樣
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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):