Tkinter按钮(Button)
按钮组件是用来添加一个Python应用程序中的按钮。这些按钮可以显示文字或图像,表达按钮的目的。当你按一下按钮时,您可以附加到一个按钮的函数或方法,该方法自动调用.
语法:
这里是一个简单的语法来创建这个widget:
w = Button ( master, option=value, ... )
参数:
master: 这代表了父窗口.
options: 下面是这个小工具最常用的选项列表。这些选项可以作为键 - 值对以逗号分隔.
| Option | Description |
|---|---|
| activebackground | Background color when the button is under the cursor. |
| activeforeground | Foreground color when the button is under the cursor. |
| bd | Border width in pixels. Default is 2. |
| bg | Normal background color. |
| command | Function or method to be called when the button is clicked. |
| fg | Normal foreground (text) color. |
| font | Text font to be used for the button's label. |
| height | Height of the button in text lines (for textual buttons) or pixels (for images). |
| highlightcolor | The color of the focus highlight when the widget has focus. |
| image | Image to be displayed on the button (instead of text). |
| justify | How to show multiple text lines: LEFT to left-justify each line; CENTER to center them; or RIGHT to right-justify. |
| padx | Additional padding left and right of the text. |
| pady | Additional padding above and below the text. |
| relief | Relief specifies the type of the border. Some of the values are SUNKEN, RAISED, GROOVE, and RIDGE. |
| state | Set this option to DISABLED to gray out the button and make it unresponsive. Has the value ACTIVE when the mouse is over it. Default is NORMAL. |
| underline | Default is -1, meaning that no character of the text on the button will be underlined. If nonnegative, the corresponding text character will be underlined. |
| width | Width of the button in letters (if displaying text) or pixels (if displaying an image). |
| wraplength | If this value is set to a positive number, the text lines will be wrapped to fit within this length. |
方法:
以下是这个小工具的常用方法:
| Medthod | Description |
|---|---|
| flash() | Causes the button to flash several times between active and normal colors. Leaves the button in the state it was in originally. Ignored if the button is disabled. |
| invoke() | Calls the button's callback, and returns what that function returns. Has no effect if the button is disabled or there is no callback. |
例子:
自行尝试下面的例子:
import Tkinter
import tkMessageBox top = Tkinter.Tk() def helloCallBack():
tkMessageBox.showinfo( "Hello Python", "Hello World") B = Tkinter.Button(top, text ="Hello,Python!少壮不努力,老大学编程.-易百在线教程 - www.yiibai.com", command = helloCallBack) B.pack()
top.mainloop()
这将产生以下结果:

Tkinter按钮(Button)的更多相关文章
- 在jQuery ajax中按钮button和submit的区别分析
在使用jQuery ajax的get方法进行页面传值,不能用submit,否则无刷新获取数据展示 点击submit提交按钮,sendPwd.php通过$_POST接收传过来的值,然后echo一段数据. ...
- .net学习之母版页执行顺序、jsonp跨域请求原理、IsPostBack原理、服务器端控件按钮Button点击时的过程、缓存、IHttpModule 过滤器
1.WebForm使用母版页后执行的顺序是先执行子页面中的Page_Load,再执行母版页中的Page_Load,请求是先生成母版页的控件树,然后将子页面生成的控件树填充到母版页中,最后输出 2.We ...
- Android 自定义控件 EditText输入框两边加减按钮Button
自己封装的一个控件:EditText两边放加减按钮Button来控制输入框的数值 Demo 下载地址: 第一版:http://download.csdn.net/detail/zjjne/674086 ...
- 关于bootstrap--表单(按钮<button>效果、大小、禁用)
1.各种标签实现按钮效果: <button class="btn btn-default" type="button">button标签按钮< ...
- cocos creator 重写源码按钮Button点击音频封装
(function(){ var Super = function(){}; Super.prototype = cc.Button.prototype; //实例化原型 Super.prototyp ...
- 前端表单中有按钮button自动提交表单
问题描述 在设计表单时,表单内有一个按钮<button>,该按钮是用来获取其他数据或执行其他操作的.并不是让他提交表单. 解决方案 1) 设置 form 的 onsubmit='retur ...
- Android 按钮 Button和ImageButton
Button -- 按钮ImageButton -- 图片按钮Button和ImageButton特征1.共有的特征都可以作为一个按钮产生点击事件2.不同点: (1)Button有text属性,Ima ...
- 36种漂亮的CSS3网页按钮Button样式
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- Bootstrap历练实例:按钮(Button)插件单个切换
单个切换 如需激活单个按钮的切换(即改变按钮的正常状态为按压状态,反之亦然),只需向 button 元素添加 data-toggle="button" 作为其属性即可,如下面实例所 ...
随机推荐
- JavaScript库基本格式写法
/********************************************************************* * JavaScript库基本格式写法 * 说明: * 由 ...
- 【剑指offer】判断一个序列是否是二叉搜索树的后序遍历,C++实现
原创文章,转载请注明出处! 本题牛客网地址 博客文章索引地址 博客文章中代码的github地址 1.题目 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果.如果是则输出Yes,否则输出N ...
- 用with来打开文本文件
with open ('text.txt') as f: for line in f.readlines(): print(line) 这种方法的好处就是如果出了异常也会自动提示报错.
- phpcms tag页调用缩略图
\phpcms\modules\content\tag.php 找到: 'title, description, url, inputtime, style' 改成:'title, thumb, de ...
- 21天学通C++_Day5
昨天停更了一天,真是羞羞啊,不过还是干了很多有意义的事的! 首先,昨天下午的时候,去参加了学校的春招!第一次参加招聘会,怕自己答不上面试官的问题,很是紧张! 和同学约的一点,结果到了发现还没开始,只能 ...
- SEO中H1标签的用法- 1
在网上找了很多关于H1标签对SEO意义的资料,不可否认H1对SEO具有重大的意义,但是具体情况每个人有每个人的见解吧.这里主要根据网上搜索的资料,以及自己的一些经验整理出来的,但是本人毕竟不是专业SE ...
- Jmeter简单的接口测试
1.新建线程组 2.编辑线程组信息 3.在线程组中添加HTTP信息头管理器 4.配置HTTP信息头管理器 参数格式配置 5.在线程组中添加HTTP请求 6.编辑HTTP请求信息 7.添加响应断言 8. ...
- BZOJ4903 UOJ300 CTSC2017 吉夫特 【Lucas定理】
BZOJ4903 UOJ300 CTSC2017 吉夫特 弱弱地放上题目链接 Lucas定理可以推一推,发现C(n,m)是奇数的条件是n" role="presentation&q ...
- .NET 中 GetProcess 相关方法的性能
.NET 的 Process 类中提供了查找进程的若干方法,其中部分方法还比较消耗性能.如果你试图优化查找进程相关方法的性能,可能本文分享的一些耗时数据可以作为参考. 性能比较 Process 类 ...
- RSA 每次公钥加密不同结果
今天服务器端一哥们突然跑过来跟我说:我发现公钥每次加密都不同结果啊? 我说:怎么可能?不同的话,私要怎么解密和验证啊? 然后我屁颠屁颠的试了下,结果发现不论在在线RSA的还是自己公司 利用同一个明文加 ...