为UI创建的Button添加属性,width,height, background.
测试代码如下:
from tkinterimport *
wnd = Tk()
btn = Button(wnd, text=“Python学习”)
btn[“width”] =20
btn[“height”] =4
btn.pack()
btn2 = Button(wnd, text=“Python学习2”)
btn2[“width”] =20
btn2[“height”] =4
btn2[“background”] =“green”
btn2.pack()
wnd.mainloop()
运行效果:
Button重点是掌握如何绑定事件,属性设置时用来美化UI的。