是否可以使按钮3同时具有更改为第二页的命令以及从文本框中清除文本的功能?
def __init__(self, parent, controller):
global entry, i, T
tk.Frame.__init__(self, parent)
self.controller = controller
S = tk.Scrollbar(self)
T = tk.Text(self)
S.pack(side=tk.RIGHT, fill=tk.Y)
T.pack(fill=tk.Y)
S.config(command=T.yview)
T.config(yscrollcommand=S.set)
T.insert(tk.END, "Available Days to take Annual Leave:\n%s\n" % DaysInWeek)
label = tk.Label(self, text="Do you want Annual Leave?")
label.pack()
entry = tk.Entry(self)
entry.pack()
button2 = tk.Button(self, text="Go", command=self.Annualinput)
button2.pack()
button3 = tk.Button(self, text="Return",
command=lambda: controller.show_frame("PageTwo"))
button3.pack()
我希望button3拥有的另一个命令是
def clear(self):
T.delete('1.0', tk.END)
我从Switch between two frames in tkinter取了切换页面代码
答案 0 :(得分:1)
分配一个可同时完成这两项操作的回调函数:
def button3_callback(*args):
T.delete('1.0', tk.END)
controller.show_frame("PageTwo")
请确保您在__init__()
函数中定义了此函数,否则T
将超出范围。