Python 图形Tkinter Button

来源:互联网 发布:网络主页版式规范 编辑:程序博客网 时间:2024/05/22 02:56
#coding=utf-8'''第一个button 例子'''#command:指定时间处理函数from Tkinter import *#定义Button的时间处理函数def helloButton():    print 'hello Button'root = Tk()#通过 command 属性来指定Button的事件处理函数Button(root,       text='点击一次控制台打印一句 hello Button',       command=helloButton       ).pack()root.mainloop()#coding=utf-8'''Button 的外观效果'''from Tkinter import *root = Tk()#flat, groove, raised, ridge, solid, or sunkenButton(root,       text='hello button',       relief=FLAT       ).pack()Button(root,       text='hello button',       relief=GROOVE       ).pack()Button(root,       text='hello button',       relief=RAISED       ).pack()Button(root,       text='hello button',       relief=SOLID       ).pack()Button(root,       text='hello button',       relief=SUNKEN       ).pack()#root.mainloop()#图像居下,居上,居右,居左,文字位于图像之上#root = Tk()Button(root,       text = 'botton',       compound = 'bottom',       bitmap = 'error'       ).pack()Button(root,       text = 'top',       compound = 'top',       bitmap = 'error'       ).pack()Button(root,       text = 'right',       compound = 'right',       bitmap = 'error'       ).pack()Button(root,       text = 'left',       compound = 'left',       bitmap = 'error').pack()Button(root,       text = 'center',       compound = 'center',       bitmap = 'error'       ).pack()#root.mainloop()'''Button 的焦点'''# focus_set:设置当前组件得到焦点#创建三个 Button,各自对应回调函数;# 将第二个 Button 设置焦点,程序运行是按“Enter”,#  判断程序的打印结果def cb1():    print 'button1 clicked'def cb2(event):    print 'button2 clicked'def cb3():    print 'button3 clicked'#root = Tk()b1 = Button(root,text = 'Button1',command = cb1)b2 = Button(root,text = 'Button2')b2.bind("<Return>",cb2)b3 = Button(root,text = 'Button3',command = cb3)b1.pack()b2.pack()b3.pack()b2.focus_set()root.mainloop()

原创粉丝点击