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" 作为其属性即可,如下面实例所 ...
随机推荐
- JMter中添加断点和关联
一. 断点 断言是什么呢,它是用来检查返回结果对不对的. 用来验证结果是否正确,如果正确的话,就代表这个请求的返回是正确的,如果没有的话就代表这个请求的结果和我们预期的不一致,这 ...
- iad 集成三两事
1. 好像是随着ios8的beta开始. iad 已经发生了一些变化. 比如找不到enable iad network 的按钮了. 貌似是不需要手动去 enable 了. 只需要嵌入 iad fra ...
- 基于Ubuntu16.04的GeForce GTX 1080驱动安装,遇到的问题及对应的解决方法
1.在主机上插上GPU之后,查看设备: $ nvidia-smi Tue Dec :: +------------------------------------------------------- ...
- vscode+Firefox实现前端移动真机测试
需要配件: 1.安装有火狐浏览器的移动端(手机); 2.安装有火狐浏览器和vscode的pc(电脑); 3.在vscode安装Live Server 插件 4.安装之后vscode右下角会有Go Li ...
- IOS开发 GCD介绍: 基本概念和Dispatch Queue
iOS的三种多线程技术 1.NSThread 每个NSThread对象对应一个线程,量级较轻(真正的多线程) 2.以下两点是苹果专门开发的“并发”技术,使得程序员可以不再去关心线程的具体使用问题 ØN ...
- SQL基础三(例子)
-----------聚合函数使用------------------------ --1.查询student表中所有学生人数 select count(stuno) from student --2 ...
- 有关linux中,<math.h>的调用方法
h{font-weight:bold;color:green;font-size:105%} p{font-size:100%} linux下C语言程序中,若要用到math.h中的函数(如:sin() ...
- PDF文档过期时间/自毁设置
不是很完美的方法,可以凑活着用: 切换到Pages预览页,右击页面选页面属性 切换到Action,选Run a Javascript,代码: // PDF JavaScript to make it ...
- linux下修改了tomcat端口之后无法访问
查看防火墙,是否将修改之后的端口加入防火墙规则内,如没有,加入规则内,重启防火墙,如果还是无法访问,请看第二步 执行bin目录下shutdown.sh脚本,如果正常关闭,则执行startup.sh脚本 ...
- 每天一个linux命令(磁盘):【转载】du 命令
Linux du命令也是查看使用空间的,但是与df命令不同的是Linux du命令是对文件和目录磁盘使用的空间的查看,还是和df命令有一些区别的. 1.命令格式: du [选项][文件] 2.命令功能 ...