您可以在同一个地方创建两个框架,并使用提升和降低方法将它们相互提升(示例取自 Bryan Oakley here 并稍作修改):
import Tkinter as tk
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.frame = tk.Frame(self)
self.frame2 = tk.Frame(self)
self.frame.place(relwidth=1, relheight=0.8, relx=0, rely=0)
self.frame2.place(relwidth=1, relheight=0.8, relx=0, rely=0)
self.label = tk.Label(self.frame, text="Hello, world")
button1 = tk.Button(self, text="Click to hide label",
command=self.hide_label)
button2 = tk.Button(self, text="Click to show label",
command=self.show_label)
self.label.pack()
button1.place(relwidth=0.5, relheight=0.15, relx=0.0, rely=0.825)
button2.place(relwidth=0.5, relheight=0.15, relx=0.5, rely=0.825)
def show_label(self, event=None):
self.frame.lift(self.frame2)
def hide_label(self, event=None):
self.frame.lower(self.frame2)
if __name__ == "__main__":
app = SampleApp()
app.mainloop()
您可以将“第一页”放在一个框架中,将“第二页”放在另一个框架中