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. 使用PLSQL客户端登录ORACLE时报ORA-12502和ORA-12545错误的解决方案

    当使用plsqldev客户端登录oracle数据库时,如果对应的tnsnames.ora中是直接使用IP地址来连接,并且未在系统的hosts文件中绑定主机名时,极易出现ORA-12502及ORA-12 ...

  2. python3爬虫-网易云排行榜,网易云歌手及作品

    import requests, re, json, os, time from fake_useragent import UserAgent from lxml import etree from ...

  3. 原生 JS 实现扫雷 (分析+代码实现)

    阅读这篇文章需要掌握的基础知识:Html5.CSS.JavaScript 在线Demo:查看 扫雷规则 在写扫雷之前,我们先了解下它的游戏规则 ● 扫雷是一个矩阵,地雷随机分布在方格上. ● 方格上的 ...

  4. LeetCode 中级 - 优势洗牌(870)

    给定两个大小相等的数组 A 和 B,A 相对于 B 的优势可以用满足 A[i] > B[i] 的索引 i 的数目来描述. 返回 A 的任意排列,使其相对于 B 的优势最大化. 示例 2: 输入: ...

  5. 笔记: 对称加密算法的PKCS5 和 PKCS7 填充

    PKCS #7 填充字符串由一个字节序列组成,每个字节填充该填充字节序列的长度. 假设,块的长度是 8, 数据长度是 5 数据:AA AA AA AA AA PKCS#7 填充 AA AA AA AA ...

  6. PHP中call user func()和call_user_func_array()调用自定义函数小结

    call_user_func() 和 call_user_func_array(),通过传入字符串函数,可以调用自定义函数,并且支持引用,都允许用户调用自定义函数并传入一定的参数: 1.mixed c ...

  7. layer父界面调用子弹窗的方法和获取子弹窗的元素值总结

    layer.open({ type: 2 ,title: false //不显示标题栏 ,closeBtn: false ,area: ['460px', '45%'] ,shade: 0.5 ,id ...

  8. jQuery树形控件zTree使用小结

    作者:Fonour 字体:[增加 减小] 类型:转载 时间:2016-08-02我要评论 这篇文章主要为大家详细介绍了jQuery树形控件zTree使用方法,zTree树插件的基本使用方法,感兴趣的小 ...

  9. div盒子水平垂直居中的方法推荐

    父盒子是position:relative 方法一:(宽高确定) div绝对定位水平垂直居中[margin 负间距], 方法二: (宽高确定) div绝对定位水平垂直居中[margin:auto实现绝 ...

  10. scala 实现日期运算

    在scala程序中,有时我们需要对日期进行运算,比如一天之前,两天之前,一个月之前等等,本博文给出了简单的实现方式 val cal = Calendar.getInstance cal.add(Cal ...