【发布时间】:2020-10-09 23:10:21
【问题描述】:
这是我的代码的一部分,我正在尝试创建一个用户输入字段,用户可以在其中编写他们希望背景颜色的类型,然后单击其下方的按钮并实现它。
我使用完全相同的代码来更改我的画笔颜色“
create_oval(color, outline) 并且它工作了,它似乎不影响背景颜色,有什么建议吗?
import tkinter
background = "white"
okno = tkinter.Tk()
okno.title("Project")
platno = tkinter.Canvas(okno, height = 300, width = 300, bg = background)
platno.pack()
def background_color():
background = vstup2.get()
vstup2.set(background)
tkinter.Label(okno,text = "Background color :", bg = "white", width = 30).pack()
vstup2 = tkinter.StringVar()
tkinter.Entry(okno,textvariable = vstup2, ).pack()
tkinter.Button(okno,width=30, text="Set the color of a background", command=background_color).pack()
【问题讨论】:
-
你想改变哪个小部件的颜色?
-
你在用
StringVar换颜色吗? -
你似乎并没有试图改变任何地方的背景。
-
此:
vstup2.set(background)应改为:platno.configure(bg=background)。同时修复你的缩进错误。
标签: python python-3.x button tkinter background-color