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. java8的新特性,Collections.sort(排序的List集合)的使用,对list封装Map里面的某个值进行排序

    --------------------------对简单list的排序---------------------------------- List<Integer> list = ne ...

  2. Git 远程推送被拒绝的一种解决方案

    今天在推送的时候发生了如下错误信息: error: 无法推送一些引用到 'https://gitee.com/von_w/demo_app.git'提示:更新被拒绝,因为您当前分支的最新提交落后于其对 ...

  3. jquery 去除空格

    /** * 是否去除所有空格 * @param str * @param is_global 如果为g或者G去除所有的 * @returns */ function Trim(str,is_globa ...

  4. C#获取本地磁盘信息

    直接上干货简单易懂 //磁盘监控(远程/本地) //需要引用System.Management.dll public class RemoteMonitoring { private static s ...

  5. 【C】三目运算符(先是问号之后又是冒号的那个)

    // 看这个例子就可以懂了 a = b == c ? d : e ; //如果 b==c,执行 a=d //否则执行 a=e //为了方便阅读,也可以改成下方代码 a = (b == c) ? d : ...

  6. Django自定制分页功能

    URL: """django_paginner URL Configuration The `urlpatterns` list routes URLs to views ...

  7. Docker入门系列02

    上篇用一个简单的示例,简单的介绍了 Dockerfile 的配置及其相关的命令.这一篇会在上篇的示例程序里,继续添加新代码及如何将单元测试也放入 Image 建立过程内. 首先,我们需要建一个新的类库 ...

  8. 十分钟部署Anemometer作为Mysql慢查询可视化系统

    前言 采用Anemometer将Mysql慢查询日志可视化,可以更便捷的查询慢查询日志,并根据时间戳进行历史查询.如下是单机版Anemometer部署的演示,实际应用中,为安全起见,建议把anemom ...

  9. CSS基础part2

    CSS属性操作-文本 文本颜色 <head> <style> p{ /*color:#8B5742 ;色码表*/ color: RGBA(255,0,0,0.5); /*调色, ...

  10. MySQL高级第二章——索引优化分析

    一.SQL性能下降原因 1.等待时间长?执行时间长? 可能原因: 查询语句写的不行 索引失效(单值索引.复合索引) CREATE INDEX index_user_name ON user(name) ...