码迷,mamicode.com
首页 > 其他好文 > 详细

tkinter - Button(1)

时间:2016-11-04 16:11:29      阅读:328      评论:0      收藏:0      [点我收藏+]

标签:print   root   int   ext   imp   error   err   and   pac   

from tkinter import *
root = Tk()

#定义按钮的回调函数
def BackCallButton():
    print("按钮回调函数")

#通过command属性指定回调函数
Btn1 = Button(root, text = "Button", command = BackCallButton).pack()

#显示Button的各个不同效果
#flat, groove, raised, ridge, solid, or sunken
Button(root,text = ‘FLAT‘,relief=FLAT).pack()
Button(root,text = ‘GROOVE‘,relief=GROOVE).pack()
Button(root,text = ‘RAISED‘,relief=RAISED).pack()
Button(root,text = ‘RIDGE‘,relief=RIDGE).pack()
Button(root,text = ‘SOLID‘,relief=SOLID).pack()
Button(root,text = ‘SUNKEN‘,relief=SUNKEN).pack()

#与Label一样,Button也可以同时显示文本与图像,使用属性compound
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()

def printEventInfo(event):
    print (‘event.time = ‘ , event.time)
    print (‘event.type = ‘ , event.type)
    print (‘event.WidgetId = ‘, event.widget)
    print (‘event.KeySymbol = ‘,event.keysym)

b = Button(root,text = ‘Infomation‘)

#bind方法,建立事件与回调函数(响应函数)之间的关系
b.bind("<Return>",printEventInfo)
b.pack()
#focus_set设置控件焦点
b.focus_set()

root.mainloop()

技术分享  

tkinter - Button(1)

标签:print   root   int   ext   imp   error   err   and   pac   

原文地址:http://www.cnblogs.com/moodsky/p/6030433.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!