Python - Tkinter Button按钮组件是用来添加一个Python应用程序中的按钮。这些按钮可以显示文字或图像,表达按钮的目的。当你按一下按钮时,您可以附加到一个按钮的函数或方法,该方法自动调用。

按钮组件是用来添加一个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()

这将产生以下结果:

最新文章

  1. Java 用自带dom解析器遍历叶子节点内容
  2. linux包之dmidecode
  3. spark 连接 mysql 数据库
  4. 【转载】git/github初级运用自如
  5. Mvc Webapi+Fiddler调试 (WebAPI 一)
  6. ASP.net MVC 无法初始化 ASP.NET Simple Membership 数据库
  7. Makefile 的使用
  8. 使用spark访问hive错误记录
  9. <resultMap>中 <collection>的使用
  10. Jquery on方法绑定事件后执行多次
  11. MyOD
  12. Python 连接 redis 模块
  13. 5、微信卡券code模式
  14. Qt ------ UDP发送不了或接收不到问题
  15. codeblocks 控制台一闪而过
  16. noip模拟题《迷》enc
  17. Servlet实现文件上传,可多文件上传
  18. log4j日志服务器配置
  19. iOS 8及以后版本 如何创建UIAlertView?
  20. 【数论】【中国剩余定理】【LCM】hdu1788 Chinese remainder theorem again

热门文章

  1. 层序遍历二叉树 完整层序重建二叉树 python
  2. 安卓开发 报错 错误:This version of android studio is incompatible with the gradle version used. 的解决
  3. librec库
  4. hexo+github部署
  5. HDU - 5887:Herbs Gathering (map优化超大背包)
  6. HihoCoder1050 树中的最长路 树形DP第三题(找不到对象)
  7. 实现同时提交多个form(基础方法) 收集(转)
  8. stm32寄存器版学习笔记07 ADC
  9. BZOJ1260 CQOI2007 涂色paint 【区间DP】
  10. 如何在 .NET 库的代码中判断当前程序运行在 Debug 下还是 Release 下