一、参数说明

语法 作用
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标签的更多相关文章

  1. class1and2_tkinter之 Label & Button 标签和按钮

    ''' # ------------------------------------------------------------ # # 1. 使用tkinter设置一个标签 # # # 设计tk ...

  2. button标签和input button

    一.定义和用法 <button> 标签定义的是一个按钮. 在 button 元素内部,可以放置文本或图像.这是<button>与使用 input 元素创建的按钮的不同之处. 二 ...

  3. <button> 标签 id 与 function 重复时发生的问题

    今天遇到一种情况,在调用js自定义方法的时候,总是提示“import:660 Uncaught TypeError: ... is not a function”. 仔细检查了代码,并没有问题.甚至把 ...

  4. 理解button标签的默认行为

    button标签的作用和它的名字一样,在绝大多数场合当做按钮来使用. 很多人在使用button按钮的时候出现过这样或者那样的问题,比如:自动提交表单.一次提交表单多次submit行为,有的浏览器下点击 ...

  5. HTML <button>标签

    如果<button>标签在<form>中不加type="button",那么默认含义是"submit". <button>标 ...

  6. Button标签自动刷新问题

    在form表单中,button标签在IE浏览器 type类型默认是button ,而在其他浏览器默认是submit. 解决方法1: 设置类型type="button" <bu ...

  7. CSS消除button标签的默认样式

    button{ /*消除button的默认样式*/ /*这种写法是对所有的button标签同时生效*/ margin: 0px; padding: 0px; /*自定义边框*/ border: 0px ...

  8. 前端 html button标签

    就是一个按钮标签 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...

  9. 使用<button></button>标签

    使用<button></button>标签一定要记住给它设置type,因为它默认的type=“submit”,会提交表单,设置如下 <button type=" ...

随机推荐

  1. css常用代码大全

    css常用代码大全,html+css代码 html+css可以很方便的进行网页的排版布局,还能减少很多不必要的代码. 一.文本设置1.font-size: 字号参数 2.font-style: 字体格 ...

  2. 使用node建立本地服务器访问静态文件

    最终目录结构 demo │ node_modules └───public │ │ index.html │ │ index.css │ └───index.js └───server.js 一.使用 ...

  3. FICO-清帐函数

    转载:https://www.cnblogs.com/caizjian/p/8067071.html https://blog.csdn.net/sapliumeng/article/details/ ...

  4. Matplotlib pyplot中title() xlabel() ylabel()无法显示中文(即显示方框乱码)的解决办法

    有趣的事,Python永远不会缺席! 如需转发,请注明出处:小婷儿的python https://www.cnblogs.com/xxtalhr/p/11020246.html 一.无法正常显示原因 ...

  5. 【leetcode】280.Wiggle Sort

    原题 Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] & ...

  6. ubuntu18.04 安装android studio

    首先从官网下载android studio:Android Studio (安装前应先安装JDK环境) 得到android-studio-ide-191.5977832-linux.tar.gz 在安 ...

  7. windows 下 redis 的安装及使用

    1.下载及安装redis 下载地址:https://github.com/dmajkic/redis/downloads 找到对应的版本下载安装 打开cmd窗口,用cd命令进入到安装redis的根目录 ...

  8. Android笔记(三十) Android中线程之间的通信(二)Handler消息传递机制

    什么是Handler 之前说过了,Android不允许主线程(MainThread)外的线程(WorkerThread)去修改UI组件,但是又不能把所有的更新UI的操作都放在主线程中去(会造成ANR) ...

  9. JAVA 判断给定目录的大小

    题目:给定一个目录,判断该目录的大小,单位为G 思路: 递归拿到目录的子文件,然后取长度,累加 public class FileDemo02 { public static void main(St ...

  10. java中javamail收发邮件实现方法

    概述 1.邮件相关的标准 厂商所提供的 JavaMail 服务程序可以有选择地实现某些邮件协议,常见的邮件协议包括: SMTP(Simple Mail Transfer Protocol) :即简单邮 ...