Tkinter 之Button标签
一、参数说明
| 语法 | 作用 |
|---|---|
| Button(root,text='xxxx') | 按钮图标显示内容 |
| Button(root,text='xxxx',height=2) | 组件的高度(所占行数) |
| Button(root,text='xxxx',width=20) | 组件的宽度(所占字符个数) |
| Button(text='xxxx',fg='blue') | 按钮字体颜色 |
| Button(root,text='xxxx',activebackground='grey') | 按钮按下时的前景字体颜色 |
| Button(root,text=‘xxxxx’,justify=tk.LEFT) | 多行文本的对齐方式 |
| Button(root,text='xxxx',pady=10) | 文本上下两侧的空格数 |
| Button(root,text='xxxx',padx=10) | 文本左右两侧的空格数(默认为1) |
| Button(root,text='xxxx',command=函数) | 按钮触发执行的命令(函数) |
| Button(root,text='xxxx',state=tk.DISABLED) | 按钮禁止点击 |
| Button(root,text='xxxx',underline=1) | 文字下划线(默认为-1) |
| Button(root,text='xxxx',author=tk.CENTER) | 文字位置 |
| Button(root,text='xxxx',textvariable=var) | 动态设置文本 |
二、代码示例
import tkinter as tk window = tk.Tk() def main():
global window
# 设置主窗体大小
winWidth = 600
winHeight = 400
# 获取屏幕分辨率
screenWidth = window.winfo_screenwidth()
screenHeight = window.winfo_screenheight()
# 计算主窗口在屏幕上的坐标
x = int((screenWidth - winWidth)/ 2)
y = int((screenHeight - winHeight) / 2) # 设置主窗口标题
window.title("Button参数说明")
# 设置主窗口大小
window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
# 设置窗口宽高固定
window.resizable(0,0)
# 设置窗口图标
window.iconbitmap("./image/icon.ico") """ button参数列表 STANDARD OPTIONS activebackground, activeforeground, anchor,
background, bitmap, borderwidth, cursor,
disabledforeground, font, foreground
highlightbackground, highlightcolor,
highlightthickness, image, justify,
padx, pady, relief, repeatdelay,
repeatinterval, takefocus, text,
textvariable, underline, wraplength WIDGET-SPECIFIC OPTIONS command, compound, default, height,
overrelief, state, width
"""
var = tk.StringVar()
var.set("提交")
tk.Button(window, text="提交", width=30, pady=5,fg="#f00", bg="#bbb",
borderwidth=0, activeforeground="yellow", activebackground="#666"
,underline=-1, command=click, textvariable=var).pack()
window.mainloop() def click():
print("click") if __name__ == '__main__':
main()
三、效果图

Tkinter 之Button标签的更多相关文章
- class1and2_tkinter之 Label & Button 标签和按钮
''' # ------------------------------------------------------------ # # 1. 使用tkinter设置一个标签 # # # 设计tk ...
- button标签和input button
一.定义和用法 <button> 标签定义的是一个按钮. 在 button 元素内部,可以放置文本或图像.这是<button>与使用 input 元素创建的按钮的不同之处. 二 ...
- <button> 标签 id 与 function 重复时发生的问题
今天遇到一种情况,在调用js自定义方法的时候,总是提示“import:660 Uncaught TypeError: ... is not a function”. 仔细检查了代码,并没有问题.甚至把 ...
- 理解button标签的默认行为
button标签的作用和它的名字一样,在绝大多数场合当做按钮来使用. 很多人在使用button按钮的时候出现过这样或者那样的问题,比如:自动提交表单.一次提交表单多次submit行为,有的浏览器下点击 ...
- HTML <button>标签
如果<button>标签在<form>中不加type="button",那么默认含义是"submit". <button>标 ...
- Button标签自动刷新问题
在form表单中,button标签在IE浏览器 type类型默认是button ,而在其他浏览器默认是submit. 解决方法1: 设置类型type="button" <bu ...
- CSS消除button标签的默认样式
button{ /*消除button的默认样式*/ /*这种写法是对所有的button标签同时生效*/ margin: 0px; padding: 0px; /*自定义边框*/ border: 0px ...
- 前端 html button标签
就是一个按钮标签 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...
- 使用<button></button>标签
使用<button></button>标签一定要记住给它设置type,因为它默认的type=“submit”,会提交表单,设置如下 <button type=" ...
随机推荐
- Git撤回已经推送(push)至远程仓库提交(commit)的版本
背景 所以,经常会遇到已经提交远程仓库,但是又不是我想要的版本,要撤下来. 回退版本一般使用git reset,又分为: # 不删除工作空间改动代码,撤销commit,不撤销git add . git ...
- iOS - The file “XXX.app” couldn’t be opened because you don’t have permission to view it.
当引入第三方的框架的时候 容易产生以下问题: The file “XXX.app” couldn’t be opened because you don’t have permission to vi ...
- HANA数据库无法停止
Symptom: 使用命令HDB stop多次,每次报错为timeout ----------------------- sdpadm@PRDDB01:/usr/sap/SDP/HDB66/prder ...
- redis过期事件回调函数,与有序集合
https://cloud.tencent.com/developer/article/1347437 python中的Redis键空间通知(过期回调) set notify-keyspace-ev ...
- Computer Vision_33_SIFT:An Improved RANSAC based on the Scale Variation Homogeneity——2016
此部分是计算机视觉部分,主要侧重在底层特征提取,视频分析,跟踪,目标检测和识别方面等方面.对于自己不太熟悉的领域比如摄像机标定和立体视觉,仅仅列出上google上引用次数比较多的文献.有一些刚刚出版的 ...
- 更改和配置本地yum源
查看yum 存放位置 [root@web01 yum.repos.d]# ll /etc/yum.repos.d/ total -rw-r--r--. root root Jun CentOS-Bas ...
- python RSA加密、解密、签名
python RSA加密.解密.签名 python中用于RSA加解密的库有好久个,本文主要讲解rsa.M2Crypto.Crypto这三个库对于RSA加密.解密.签名.验签的知识点. 知识基础 加密是 ...
- 图片处理:html文本获取图片Url,判断图片大小,存数据库
1.从html文本获取图片Url /** * html文本中取出url链接 */ public class Url { public static void main(String[] args) { ...
- Java原子类--AtomicLongFieldUpdater
转载请注明出处:http://www.cnblogs.com/skywang12345/p/3514623.html AtomicLongFieldUpdater介绍和函数列表 AtomicLongF ...
- Redis vs kafka
kafka的订阅可以重复消费,但redis的不行,只能收到订阅之后发布的数据 redis无法实现消息堆积和回溯 1 Redis是个数据库,可以改.查,而KFAKA 不能改查2 redis是内存数据库, ...