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. Spring整合Mybatis SQL语句的输出

    [1.修改Spring-Mybatis] <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSes ...

  2. MySQL学习之流程结构

    流程结构 流程结构:代码的执行顺序. if分支 根据要求选择合适的执行部分. 基本语法 if在MySQL中有两种基本用法 1.用在select查询当中,当作一种条件来进行判断. 基本语法:if(条件, ...

  3. python开发的学生管理系统

    python开发的学生管理系统(基础版) #定义一个函数,显示可以使用的功能列表给用户 def showInfo(): print("-"*30) print(" 学生管 ...

  4. Java线程池的创建详解

    本篇文章主要总结了Java创建线程池的三种方式以及线程池参数的详细说明,对线程池感兴趣的同学可以作为参考学习. 1)通过工具类java.util.concurrent.Executors的静态方法来创 ...

  5. 一图看懂mybatis执行过程

    一图看懂mybatis执行过程,不再懵B了

  6. 通过devmem访问物理地址

    目录 1.写在前面 2.devmem使用 3.应用层 4.内核层 1.写在前面 最近在调试时需要在用户层访问物理内存,发现应用层可以使用devmem工具访问物理地址.查看源码,实际上是对/dev/me ...

  7. C语言基础——链表的相关操作

    1 #include <stdio.h> #include <malloc.h> #include <string.h> #include <math.h&g ...

  8. Tomcat7 调优及 JVM 参数优化

      Tomcat 的缺省配置是不能稳定长期运行的,也就是不适合生产环境,它会死机,让你不断重新启动,甚至在午夜时分唤醒你.对于操作系统优化来说,是尽可能的增大可使用的内存容量.提高CPU 的频率,保证 ...

  9. asp.net微信公众平台本地调试设置

    1.首先要开启内网穿透功能,我这边使用自己搭建的ngrok内网穿透服务(具体如何搭建ngrok内网穿透服务,另开一篇说) 2.开启内网穿透后,即可实现互联网访问 www.tbkmama.cn 指向 1 ...

  10. python中利用少量代码快速实现从类对象中抽取所需属性的一种实践

    项目中有可能会碰到这样一种场景: 根据一个id,查询得到和id对应的完整数据信息存储对象,比如书籍id到书籍详细信息,用户id到用户详细信息等,详细信息字段可能包括几十甚至上百个数据字段,真正需要返回 ...