我正在用Python Idle编写一个Tkinter GUI,在我的GUI启动时,我想在第一页上显示一个图形,并在该图形上显示一个硬编码波形。当GUI用户按下页面上的按钮时,我实质上希望绘制一个不同的方程式。在创建按钮时,如果我在Tkinter.Button的命令部分中没有lambda,则按钮按下方程式将填充图形。如果我在命令部分没有lambda,则按该按钮不会对图形产生任何影响。请帮助我弄清楚如何根据按钮的按下来更改图。
class FirstPage(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
self.controller = controller
##Label For this page
label = tk.Label(self,text = 'Data Input',font = TITLE_FONT)
label.pack(side = 'top',anchor = 'w',padx = 10,pady= 1)
##Button to go to next page
button1 = tk.Button(self, text="Go to FFT Page",
command=lambda: controller.show_frame("SecondPage"))
button1.pack(side = 'left', anchor = 'n', padx = 10,pady = 10)
##Adding figure that will show raw data
f_front = Figure(figsize = (12.92, 4.3), dpi = 80)
FirstPage.a = f_front.add_subplot(111)
canvas_f_front = FigureCanvasTkAgg(f_front,self)
canvas_f_front.get_tk_widget().place(relx = 0.02, rely = 0.55)
FirstPage.a.set_title('Raw Wav File',fontsize = 16)
FirstPage.a.set_xlabel('Samples',fontsize = 14)
FirstPage.a.set_ylabel('Amplitude',fontsize = 14)
self.Raw_Plotting(FirstPage.a)
button2 = tk.Button(self, text="Go to FFT Page",
command = lambda: self.File_Button_Push(FirstPage.a))
button2.pack(side = 'right', anchor = 'n', padx = 10,pady = 10)
def Raw_Plotting(self, subplot):
n = np.arange(0,10000)
tS = 1/44100;
x = 1*np.cos(2*np.pi*100*np.dot(tS,n))+2*np.cos(2*np.pi*90*np.dot(tS,n))
subplot.plot(x)
def File_Button_Push(self, subplot):
n = np.arange(0,10000)
x = n * 1
subplot.plot(x)