【发布时间】:2017-08-14 00:42:11
【问题描述】:
每当用户单击检查按钮时,我都会尝试更改 Tkinter 标签的颜色。我无法正确编写函数并将其连接到命令参数。
这是我的代码:
import Tkinter as tk
root = tk.Tk()
app = tk.Frame(root)
app.pack()
label = tk.Label(app, bg="white", pady=5, font=(None, 1), height=20, width=720)
checkbox = tk.Checkbutton(app, bg="white", command=DarkenLabel)
label.grid(row=0, column=0, sticky="ew")
checkbox.grid(row=0, column=0, sticky="w")
def DarkenLabel():
label.config(bg="gray")
root.mainloop()
谢谢
【问题讨论】:
-
它工作正常,您只需将
DarkenLabel函数移动到将其用作命令变量的位置。您是否看到它无法正常工作或在运行脚本时遇到异常? -
真的就这么简单!