Python3 Tkinter-Button
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的更多相关文章
- python3+tkinter实现的黑白棋,代码完整 100%能运行
今天分享给大家的是采用Python3+tkinter制作而成的小项目--黑白棋 tkinter是Python内置的图形化模块,简单易用,一般的小型UI程序可以快速用它实现,具体的tkinter相关知识 ...
- Python3 tkinter基础 Listbox Button 点击按钮删除选中的单个元素
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3 tkinter基础 Button command 单击按钮 在console中打印文本
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3 tkinter基础 Button text,fg 按钮上显示的文字 文字的颜色
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3 tkinter基础 Button bg 按钮的背景颜色
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- python3 tkinter模块
一.tkinter 1.tkinter--tool kit interface工具包接口,用于GUI(Graphical User Interface)用户图形界面, 2.python3.x把Tkin ...
- Python3 tkinter基础 Tk quit 点击按钮退出窗体
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3 tkinter基础 Text window 文本框中插入按钮
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- python3 tkinter添加图片和文本
在前面一篇文章基础上,使用tkinter添加图片和文本.在开始之前,我们需要安装Pillow图片库. 一.Pillow的安装 1.方法一:需要下载exe文件,根据下面图片下载和安装 下载完 ...
- python3 Tkinter GUI 试水
from tkinter import * #导入tkinter下所有包,用于GUI开发#窗口创建tk=Tk()cans=Canvas(tk,width=400,height=400)#定义窗口规格c ...
随机推荐
- (二、下) springBoot 、maven 、mysql、 mybatis、 通用Mapper、lombok 简单搭建例子 《附项目源码》
接着上篇文章中 继续前进. 一.在maven 的pom.xm中添加组件依赖, mybatis通用Mapper,及分页插件 1.mybatis通用Mapper <!-- mybatis通用Mapp ...
- 关于Quartz 2D绘图的简单使用
Quartz 2D是一个二维图形绘制引擎,支持iOS环境和Mac OS X环境,Quartz 2D的API可以实现许多功能,如:基于路径的绘图.透明度.阴影.颜色管理.反锯齿.PDF文档生成和PDF元 ...
- Python-爬虫小计
# -*-coding:utf8-*-import requestsfrom bs4 import BeautifulSoupimport timeimport osimport urllibimpo ...
- xshell安装教程
Xshell安装使用教程 Xshell 是一个强大的安全终端模拟软件,它支持SSH1, SSH2, 以及Microsoft Windows 平台的TELNET 协议.Xshell 通过互联网到远程主机 ...
- Appointment Helper
using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk.Que ...
- Django学习之mysql应用基础
使用pip 安装mysql pip install mysql 使用命令行打开数据库且选择使用已有的数据库 显示已有数据库show databases; 选择已有数据库 use s23; 显示s23数 ...
- Celery的基本使用
Celery 1.什么是Celery Celery是一个简单.灵活且可靠的,处理大量消息的分布式系统,专注于实时处理的异步任务队列,同时也支持任务调度. 用Python写的执行 定时任务和异步任务的框 ...
- jetty 服务器配置无项目名
运行命令:java -jar start.jar jetty.http.port=8080,建议写成bat文件来运行. 部署无项目名的项目,将war包改成root,复制到webapps, 然后在jet ...
- PTA基础编程题目集7-4 BCD解密
BCD数是用一个字节来表达两位十进制的数,每四个比特表示一位.所以如果一个BCD数的十六进制是0x12,它表达的就是十进制的12.但是小明没学过BCD,把所有的BCD数都当作二进制数转换成十进制输出了 ...
- GoLand软件免激活的使用方法
由于官方的Goland软件,免费使用期限是30天.如果你不购买产品的话,就需要不断的卸载和重装软件才能使用.不过要是您的资金允许的话,可以去http://www.jetbrains.com/go/bu ...