python 图形用户界面tkinter之按钮Button的使用 | 您所在的位置:网站首页 › iOS1511 › python 图形用户界面tkinter之按钮Button的使用 |
创建和设置窗口
from tkinter import *
#创建窗口对象
root = Tk()
#窗口属性设置
root.title ('窗口标题')
root.geometry('300x400')
root.configure(bg='blue')
root.iconbitmap(r'C:\Users\Administrator\Desktop\iVista 2 OS X Icons ico\ico\Burn.ico')
Mark:使用了窗口的iconbitmap函数更改了图标。 按钮Button属性1 def print1(): print('你好') button = Button(root,text='打印', font=('楷体',20),fg='red',bg='black', anchor='center',command=print1, #command是命令的意思 height=1,width=5,bd=6) button.pack() root.mainloop()效果图示 效果图示
动态的修改按钮Button的属性 def print1(): #button['text']='Now you see me' button.configure(text='Now you see me') button = Button(root,text='打印', font=('楷体',30),fg='red',bg='black', anchor='center',command=print1, height=1,width=20,bd=6) button.pack() root.mainloop()效果图示
小结:通过Button对象,我们可以在窗口中设置不同外观的按钮。而且,点击Button按钮,可以执行函数中的代码块。 |
CopyRight 2018-2019 实验室设备网 版权所有 |