Python Tkinter-Event
1.点击
from tkinter import *
root=Tk()
def printCoords(event):
print(event.x,event.y)
bt1=Button(root,text='leftmost button')
bt1.bind('<Button-1>',printCoords)
bt2=Button(root,text='middle button')
bt2.bind('<Button-2>',printCoords)
bt3=Button(root,text='rightmost button')
bt3.bind('<Button-3>',printCoords)
bt4=Button(root,text='double button')
bt4.bind('<Double-Button-1>',printCoords)
bt5=Button(root,text='triple button')
bt5.bind('<Triple-Button-1>',printCoords)
bt1.grid()
bt2.grid()
bt3.grid()
bt4.grid()
bt5.grid()
root.mainloop()

2.移动
from tkinter import *
root=Tk()
def printCoords(event):
print(event.x,event.y)
bt1=Button(root,text='leftmost button')
bt1.bind('<B1-Motion>',printCoords)
bt2=Button(root,text='middle button')
bt2.bind('<B2-Motion>',printCoords)
bt3=Button(root,text='rightmost button')
bt3.bind('<B3-Motion>',printCoords)
bt1.grid()
bt2.grid()
bt3.grid()
root.mainloop()

3.释放
from tkinter import *
root=Tk()
def printCoords(event):
print(event.x,event.y)
bt1=Button(root,text='leftmost button')
bt1.bind('<ButtonRelease-1>',printCoords)
bt2=Button(root,text='middle button')
bt2.bind('<ButtonRelease-2>',printCoords)
bt3=Button(root,text='rightmost button')
bt3.bind('<ButtonRelease-3>',printCoords)
bt1.grid()
bt2.grid()
bt3.grid()
root.mainloop()

4.进入
from tkinter import *
root=Tk()
def printCoords(event):
print(event.x,event.y)
bt1=Button(root,text='leftmost button')
bt1.bind('<Enter>',printCoords)
bt1.grid()
root.mainloop()

5.离开
from tkinter import *
root=Tk()
def printCoords(event):
print(event.x,event.y)
bt1=Button(root,text='leftmost button')
bt1.bind('<Leave>',printCoords)
bt1.grid()
root.mainloop()

6.响应特殊键
from tkinter import *
root=Tk()
def printCoords(event):
print(event.x,event.y)
bt1=Button(root,text='leftmost button')
bt1.bind('<BackSpace>',printCoords)
bt2=Button(root,text='middle button')
bt2.bind('<Return>',printCoords)
bt3=Button(root,text='rightmost button')
bt3.bind('<F5>',printCoords)
bt1.focus_set()
bt1.grid()
bt2.grid()
bt3.grid()
root.mainloop()

7.响应所有按键
from tkinter import *
root=Tk()
def printCoords(event):
print(event.x,event.y)
bt1=Button(root,text='leftmost button')
bt1.bind('<Key>',printCoords)
bt1.focus_set()
bt1.grid()
root.mainloop()

8.响应指定按键
from tkinter import *
root=Tk()
def printCoords(event):
print(event.x,event.y)
bt1=Button(root,text='leftmost button')
bt1.bind('a',printCoords)
bt2=Button(root,text='middle button')
bt2.bind('<space>',printCoords)
bt3=Button(root,text='rightmost button')
bt3.bind('<less>',printCoords)
bt1.focus_set()
bt1.grid()
bt2.grid()
bt3.grid()
root.mainloop()

响应a
空格
小于号
9.响应组合键
from tkinter import *
root=Tk()
def printCoords(event):
print(event.x,event.y)
bt1=Button(root,text='leftmost button')
bt1.bind('<Control-Alt-c>',printCoords)
bt1.focus_set()
bt1.grid()
root.mainloop()

10.改变组件大小事件
from tkinter import *
root=Tk()
def printCoords(event):
print(event.width,event.height)
bt1=Button(root,text='leftmost button')
bt1.bind('<Configure>',printCoords)
bt1.focus_set()
bt1.grid()
root.mainloop()

11.两个事件绑定到一个控件
from tkinter import *
root=Tk()
def printEvent(event):
print('<Key>',event.keycode)
def printReturn(event):
print('<Return>',event.keycode)
root.bind('<Key>',printEvent)
root.bind('<Return>',printReturn)
root.mainloop()

Python Tkinter-Event的更多相关文章
- Python Tkinter基础控件入门实例
分享一个Python Tkinter基础控件用法的入门例子,包括窗口的显示.显示内置图片.弹出窗口.菜单等. 例子,Python Tkinter基础控件的用法 # -*- coding: utf-8 ...
- Python Tkinter 学习成果:点歌软件music
笔者工作业余时间也没什么爱好,社交圈子也小,主要娱乐就是背着自己带电瓶的卖唱音响到住地附近找个人多的位置唱唱KtV. 硬件上点歌就用笔记本电脑,歌曲都是网上下载的mkv格式的含有两个音轨的视频.因此点 ...
- Python Tkinter Entry(文本框)
Python学习记录--关于Tkinter Entry(文本框)的选项.方法说明,以及一些示例. 属性(Options) background(bg) borderwidth(bd) cursor e ...
- python tkinter Listbox用法
python tkinter组件的Listbox的用法,见下面代码的演示: from tkinter import * root=Tk() v=StringVar() #Listbox与变量绑定' l ...
- python Tkinter之Button
Button小部件是一个标准的Tkinter的部件,用于实现各种按钮.按钮可以包含文本或图像,您可以调用Python函数或方法用于每个按钮. Tkinter的按钮被按下时,会自动调用该函数或方法. 该 ...
- python gui tkinter快速入门教程 | python tkinter tutorial
本文首发于个人博客https://kezunlin.me/post/d5c57f56/,欢迎阅读最新内容! python tkinter tutorial Guide main ui messageb ...
- Python tkinter模块弹出窗口及传值回到主窗口操作详解
这篇文章主要介绍了Python tkinter模块弹出窗口及传值回到主窗口操作,结合实例形式分析了Python使用tkinter模块实现的弹出窗口及参数传递相关操作技巧,需要的朋友可以参考下 本文实例 ...
- Python Tkinter 文本框(Entry)
Python Tkinter 文本框用来让用户输入一行文本字符串. 你如果需要输入多行文本,可以使用 Text 组件. 你如果需要显示一行或多行文本且不允许用户修改,你可以使用 Label 组件. 语 ...
- Python Tkinter 窗口创建与布局
做界面,首先需要创建一个窗口,Python Tkinter创建窗口很简单:(注意,Tkinter的包名因Python的版本不同存在差异,有两种:Tkinter和tkinter,读者若发现程序不能运行, ...
- Python tkinter 实现简单登陆注册 基于B/S三层体系结构,实现用户身份验证
Python tkinter 实现简单登陆注册 最终效果 开始界面 注册 登陆 源码 login.py # encoding=utf-8 from tkinter import * from ...
随机推荐
- .Net core 使用NPOI 直接导入Excel到数据库(即不先将Excel保存到服务器再读取文件到数据库)
/// <summary> /// 导入信息 /// </summary> /// <param name="file"></param& ...
- 【Linux】管理文件系统
文件系统概念: 文件系统是指文件的组织与管理结构,是一个有关于磁盘中各种有用信息的记录——即是保存以下信息的结构记录表 当前所使用磁盘的容量信息 磁盘的可用信息,包括已占用和剩余的空间: 文件与目录的 ...
- Linux Centos平台下安装Nginx
以home下安装为例,切换到home目录下 cd /home 安装依赖 nginx相关依赖 yum -y install make gcc gcc-c++ openssl openssl-devel ...
- CentOS 7 Minimal 安装JDK 1.8
真好最近比较闲,打算在linux 的CentOS 7 Minimal版本试着搭建hadoop环境学习学习,当然第一步就是在CentOS 7 Minimal 安装JDK 1.8环境.其实老早就打算了解一 ...
- transition(过渡)
transition:过渡 渡过渡原理:原始状态a状态-向-最终结束状态b状态 格式:transition: all 1s linear; 过渡的四个参数: 1.参与过渡的属性(属性(width)/a ...
- react脚手架环境搭建流程
1.安装与配置node.js:1.1软件下载地址:https://nodejs.org/en/,推荐下载.msi文件,其中npm已经集成在了node.js中.1.2 双击下载的.msi文件进行安装,安 ...
- CentOS6编译安装gcc高版本
编译安装gcc高版本 因CentOS中gcc版本仅有4.4,故编译安装gcc高版本. 安装依赖库(如果你已安装过gcc低版本,可跳过这步) yum install glibc-static libst ...
- 树莓派安装DNSMASQ服务
功能: DNSMASQ是一款高性能的.小型的DNS服务器软件. * 缓存域名.IP地址,本地缓存解析的地址. * DHCP服务 1.安装 sudo apt-get update sudo apt-ge ...
- 使用Selenium时,如何选择ChromeDriver驱动版本对应Chrome浏览器版本
ChromeDriver版本 支持的Chrome版本 v2.46 v72-74 v2.45 v71-73 v2.44 v70-72 v2.43 v69-71 v2.42 v68-70 v2.41 ...
- Python学习:16.Python面对对象(三、反射,构造方法,静态字段,静态方法)
一.构造方法 在使用类创建对象的时候(就是类后面加括号)就自动执行__init__方法. class A: def __init__(self): print('A') class B: def __ ...