【发布时间】:2019-02-23 12:36:48
【问题描述】:
我无法让按钮在 python 3 中按预期工作。也就是说,当按下它时,它会将圆圈的颜色从一种颜色更改为另一种颜色,从红色开始。然而,当我运行这个程序时,它只是以白色而不是红色开始,按下按钮也不会改变圆圈的颜色,我很困惑为什么。
from tkinter import *
def changeColor():
test.itemconfig(circle, fill = "blue")
def changeColor2():
test.itemconfig(circle, fill = "white")
root = Tk()
test = Canvas(root, width = 50, height = 50)
test.pack()
circle = test.create_oval(0, 0, 25, 25,fill="red")
button = Button(root,text="",command=changeColor(),bg= "blue")
button2= Button(root,text="",command=changeColor2(),bg= "white")
button.pack()
button2.pack()
root.mainloop()
【问题讨论】:
标签: python tkinter tkinter-canvas