1.绑定事件处理函数

from tkinter import *

def hello():
    print('Hello!')

root=Tk()
button=Button(root,text='click me!',command=hello)
button.pack()
root.mainloop()

2.按钮样式

from tkinter import *

def hello():
    print('Hello!')

root=Tk()
button1=Button(root,text='click me!',command=hello,relief=FLAT)
button1.pack()
button2=Button(root,text='click me!',command=hello,relief=GROOVE)
button2.pack()
button3=Button(root,text='click me!',command=hello,relief=RAISED)
button3.pack()
button4=Button(root,text='click me!',command=hello,relief=RIDGE)
button4.pack()
button5=Button(root,text='click me!',command=hello,relief=SOLID)
button5.pack()
button6=Button(root,text='click me!',command=hello,relief=SUNKEN)
button6.pack()
root.mainloop()

3.图像

button也有bitmap,compound

4.焦点

from tkinter import *

def hello():
    print('Hello!')

def b2(event):
    print(event,' is clicked.')

root=Tk()
button1=Button(root,text='click me!',command=hello)
button1.pack()
button2=Button(root,text='click me!')
button2.bind('<Return>',b2)
button2.pack()

button2.focus_set()
button1.focus_set()

root.mainloop()

5.宽高

b.configure=(width=30,heigth=100)

也可在定义的时候确定

6.Button文本在控件上显示的位置

from tkinter import *

def hello():
    print('Hello!')

root=Tk()
button1=Button(root,text='click me!',command=hello,anchor='ne',width=30,height=4)
button1.pack()

root.mainloop()

n(north),s(south),w(west),e(east),ne(north east),nw,se,sw

7.改变颜色

from tkinter import *

def hello():
    print('Hello!')

root=Tk()
button1=Button(root,text='click me!',command=hello,fg='red',bg='blue')
button1.pack()

root.mainloop()

8.边框

from tkinter import *

def hello():
    print('Hello!')

def b2(event):
    print(event,' is clicked.')

root=Tk()

for b in [0,1,2,3,4]:
    Button(root,text=str(b),bd=b).pack()

root.mainloop()

9.状态

from tkinter import *

def hello():
    print('Hello!')

def b2(event):
    print(event,' is clicked.')

root=Tk()

for r in ['norma','active','disabled']:
    Button(root,state=r,text=r).pack()

root.mainloop()

10.绑定变量

from tkinter import *

root=Tk()

def change():
    if b['text']=='text':
        v.set('change')
    else:
        v.set('text')

v=StringVar()
b=Button(root,textvariable=v,command=change)
v.set('text')
b.pack()

root.mainloop()

 

Python3 Tkinter-Button的更多相关文章

  1. python3+tkinter实现的黑白棋,代码完整 100%能运行

    今天分享给大家的是采用Python3+tkinter制作而成的小项目--黑白棋 tkinter是Python内置的图形化模块,简单易用,一般的小型UI程序可以快速用它实现,具体的tkinter相关知识 ...

  2. Python3 tkinter基础 Listbox Button 点击按钮删除选中的单个元素

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  3. Python3 tkinter基础 Button command 单击按钮 在console中打印文本

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  4. Python3 tkinter基础 Button text,fg 按钮上显示的文字 文字的颜色

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  5. Python3 tkinter基础 Button bg 按钮的背景颜色

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. python3 tkinter模块

    一.tkinter 1.tkinter--tool kit interface工具包接口,用于GUI(Graphical User Interface)用户图形界面, 2.python3.x把Tkin ...

  7. Python3 tkinter基础 Tk quit 点击按钮退出窗体

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  8. Python3 tkinter基础 Text window 文本框中插入按钮

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  9. python3 tkinter添加图片和文本

    在前面一篇文章基础上,使用tkinter添加图片和文本.在开始之前,我们需要安装Pillow图片库. 一.Pillow的安装 1.方法一:需要下载exe文件,根据下面图片下载和安装       下载完 ...

  10. python3 Tkinter GUI 试水

    from tkinter import * #导入tkinter下所有包,用于GUI开发#窗口创建tk=Tk()cans=Canvas(tk,width=400,height=400)#定义窗口规格c ...

随机推荐

  1. Oracle 体系结构四 逻辑和物理存储结构之间的关系

    Oracle数据库从物理存储中完全抽象出逻辑存储.逻辑数据存储采用“段”的形式.段的类型有很多种:典型的段是“表”.这些段以物理形式存储在数据文件中.通过表空间将逻辑存储从物理存储中抽象出来.逻辑结构 ...

  2. iOS:SQL

    iOS虽然也有SQL,不过用得少(至少我目前是这样).大数据直接丢给后台,小的用Plist足矣. 再退一步,有FMDB,原生的也用得少了. 下面是之前学SQL时候的笔记. 1.创建 1-1).打开:  ...

  3. 用java集合模拟登录和注册功能

    package com.linkage.login; import java.util.HashMap;import java.util.Iterator;import java.util.Map;i ...

  4. Xdebug 备注

    安装步骤: 查看自己的环境是否已安装 Xdebug ,查看方法:使用phpinfo(),搜索 Xdebug 如果没有 如图: 如果没有:下一步确定你的PHP版本信息: Xdebug下载地址 https ...

  5. Linux基础(03)、常用基础指令和操作

    目录 一.什么是Linux 二.常用基础指令 2.1.vi编辑 2.2.Linux文件类型 2.3.常用指令:增.删.改.查.其他 三.Linux的目录和权限 3.1.目录 3.2.权限 3.3.修改 ...

  6. iOS 12 真机调试 Xcode 9 提示 Could not locate device support files.

    升级 iOS 12 之后,使用 Xcode 9 真机调试会提示错误: Could not locate device support files. This iPhone 6 Plus is runn ...

  7. 【Spark】Spark性能优化之Whole-stage code generation

    一.技术背景 Spark1.x版本中执行SQL语句,使用的是一种最经典,最流行的查询求职策略,该策略主要基于 Volcano Iterator Model(火山迭代模型).一个查询会包含多个Opera ...

  8. 用JavaScript动态实现单元格合并

    不太想描述,大家自行理解吧,这样可能记忆会深一点儿- <script type="text/javascript"> function mergeCells(){ va ...

  9. HyperLedger Fabric 1.4 Solo模式简介(10.1)

    Solo模式指单节点通信模式,该环境中只有一个排序(orderer)服务,从节点(peer)发送来的消息由一个orderer进行排序和产生区块:由于排序(orderer)服务只有一个orderer为所 ...

  10. 分享Centos6.5升级glibc过程

    默认的Centos6.5 glibc版本最高为2.12, 而在进行Nodejs开发时项目所依赖的包往往需要更高版本的glibc库支持, 因此在不升级系统的前提下, 需要主动更新系统glibc库. 一般 ...