【发布时间】:2021-10-20 13:30:59
【问题描述】:
我正在看这个如何制作图像查看器的教程:
基本上我的问题是这部分代码是否被认为是递归的以及为什么:
def forward(image_number):
global my_label
global button_forward
global button_back
my_label.grid_forget()
my_label = tk.Label(image=image_list[image_number-1])
button_forward = tk.Button(root, text=">>", command=lambda:forward(image_number+1)) #is this recursive?
button_back = tk.Button(root, text="<<", command=lambda:back(image_number-1))
【问题讨论】:
-
离题了,但是每次点击都创建一个新按钮是非常糟糕的做法。应该简单地改用
button.config(command=...)。
标签: python python-3.x tkinter recursion lambda