我试图在用户点击检查按钮时更改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()
Run Code Online (Sandbox Code Playgroud)
谢谢