我是一个python自学者。我一直在练习。
我的想法是创建一个弹出式GUI,按钮可以改变画布的颜色。在from Tkinter import *
import ttk
import tkMessageBox
root = Tk()
root.title("Colour!")
canvasColor = "yellow"
def buttonRed() :
canvas = Canvas(root, bg = "red", height=100, width=100)
canvas.grid(row=0,column=2)
button = ttk.Button(root, text="Red", command = buttonRed)
button.grid(row=2,column=1)
button2 = ttk.Button(root, text ="Green", command = buttonGreen)
button2.grid(row=2,column=2)
button3 = ttk.Button(root, text="Blue", command = buttonBlue)
button3.grid(row=2,column=3)
canvas = Canvas(root, bg = canvasColor, height=200, width=200)
canvas.grid(row=0,column=2)
root.configure(background='white')
root.mainloop()
我还没有输入绿色和蓝色按钮命令,但是我不想在单击颜色按钮时创建一个新画布,我只想更改默认画布颜色。在
任何帮助都将不胜感激!
提前谢谢。在