Python 图形Tkinter Button
2017-08-03 15:12
357 查看
#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 sunken Button(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()
相关文章推荐
- Python3 Tkinter基础 Canvas Button 点击按钮删除画布中的所有图形
- Python 图形编辑 Tkinter Button (二)
- 鱼c笔记——Python的GUI编程(二):Tkinter的两大常用组件Label和Button
- python开发之tkinter实现图形随鼠标移动的方法
- Python图形界面编程---Tkinter模块使用
- Python3 Tkinter基础 Button Label Frame 单击按钮,Label中显示的文字更换 StringVar textvariable
- Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Button的command/Label/PhotoImage/封装为类)——Jason niu
- Python图形GUI工具包tkinter如何调整元件在窗口中的位置几何布局管理
- Python3 Tkinter基础 Checkbutton Label Label显示是否被选中
- 熟悉python中的tkinter图形包--(写一个参数计算器)
- Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(LabelFrame/Checkbutton/Radiobutton)——Jason niu
- python-tkinter-Button
- Python3 Tkinter基础 Button text,fg在窗体中添加一个按钮,在按钮上显示文字 并 设置文字的颜色
- python之图形界面GUI开发 Tkinter 2014-4-7
- Python3 Tkinter基础 Radiobutton 设置indicatoron=False 改变按钮的外观 从圆形变为button的形状
- Python图形GUI工具包tkinter如何调整元件在窗口中的位置几何布局管理
- Python3 Tkinter基础 Button command在窗体中添加一个按钮,单击按钮 在IDLE中打印一行字
- Python实现在tkinter中使用matplotlib绘制图形的方法示例
- Python的TkinterButton做为父窗口
- Python3 Tkinter基础 LabelFrame Radiobutton 形成两组不相互限制的单选按钮