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=" ...
随机推荐
- 数据结构与算法(周测3-Huffman树)
判断题 1.Given a Huffman tree for N (≥2) characters, all with different weights. The weight of any non- ...
- Python-pptx库的运用
Win32com该库需要调用Microsoft PowerPoint,我将重新安装计算机Win 10,简单安装了pycharm的最新版本,然后发现创建的项目与之前的创建的项目结构不同.还有更多这样的事 ...
- Qt定时器
PS: 本案例使用的是Qt 4.8.4版本,不同版本代码可能会有差异. 第一步: // 重写此虚函数(继承自QObject) virtual void timerEvent(QTimerEvent* ...
- 【leetcode】280.Wiggle Sort
原题 Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] & ...
- Python面向对象之进阶
一.property 内置函数 装饰器的使用:所有的装饰器函数.方法.类的上一行直接@装饰器的名字 装饰器的分类: ① 装饰函数 ② 装饰方法 ③ 装饰类 property 是一个装饰器函数 @pro ...
- git使用方法(持续更新)
2018/5/9 最基本的操作: 添加文件.文件夹.所有文件: git add test.py //添加单个文件 git add src //添加文件夹 git add . ...
- Linux proc filesystem (procfs)
参考:/proc /proc简介 本文着重关注/proc目录,查看其中文件并熟悉它. /proc目录存在于所有Linux系统上,无论什么发行版或体系结构.首先,必须澄清一个误解: 就文件系统这一术语而 ...
- STM32定时器配置(TIM1、TIM2、TIM3、TIM4、TIM5、TIM8)高级定时器+普通定时器,定时计数模式下总结
文章结构: ——> 一.定时器基本介绍 ——> 二.普通定时器详细介绍TIM2-TIM5 ——> 三.定时器代码实例 一.定时器基本介绍 之前有用过野火的学习板上面讲解很详细,所以 ...
- Centos7安装教程
1.下载centos7的镜像 到华为云镜像官方网站下载https://mirrors.huaweicloud.com/ 2.创建虚拟机并载入镜像 3.开启虚拟机,正式安装 选择第一项:Install ...
- JS与小程序页面生命周期
Page({ /** * 页面的初始数据 */ data: { }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 生命周 ...