【发布时间】:2021-08-24 01:44:11
【问题描述】:
代码如下:
import tkinter as tk
app = tk.Tk()
container = tk.Frame(app, bg="yellow")
container.pack(side=tk.LEFT)
children = []
for i in range(2):
child = tk.Frame(container, bg="red", height=30, width=30)
child.pack(side=tk.LEFT)
children.append(child)
def on_key_press(event):
children[-1].destroy()
del children[-1:]
app.bind('<KeyPress>', on_key_press)
#children[0].destroy() <------- This works and does not leave a yellow square behind.
#children[1].destroy()
按任意键两次会留下一个黄色方块(我假设来自容器)。发生了什么?
如果我取消注释上面的注释代码,我在运行代码时看不到黄色方块。
【问题讨论】:
-
一切都会在后面留下一个黄色方块。那是他们主人的颜色