我試圖重現(xiàn)經(jīng)典的“切換幀”示例。我正在嘗試包括幾個tkk小部件,并已使用.grid()而不是.pack()。切換幀效果很好,但是,我raising在tkk小部件上遇到了麻煩。import Tkinter as tkimport ttkfrom matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2TkAgg)import matplotlib.pyplot as pltimport numpy as npclass SampleApp(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) container = tk.Frame(self) container.grid() container.grid_rowconfigure(0, weight=1) container.grid_columnconfigure(0, weight=1) self.frames = {} for F in (StartPage, PageOne): page_name = F.__name__ frame = F(parent=container, controller=self) self.frames[page_name] = frame frame.grid(row=0, column=0, sticky="nsew") self.show_frame("StartPage") def show_frame(self, page_name): '''Show a frame for the given page name''' frame = self.frames[page_name] frame.tkraise()class StartPage(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.controller = controller self.window = parent label = tk.Label(self, text="This is the start page") label.grid(pady=10) button1 = tk.Button(self, text="Go to Page One", command=lambda: controller.show_frame("PageOne")) button1.grid() self.create_widgets()如果運行此命令,您會發(fā)現(xiàn)我可以完美地從StartPage和PageOne更新Pages,但是繪圖不會從Sin變?yōu)镃osin!為什么?
添加回答
舉報
0/150
提交
取消