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 ...
随机推荐
- 容易忽略的expect脚本问题,暗藏的僵尸进程,wait命令不要漏掉
问题描述 前几天有个小需求,用到expect脚本去循环的发送一些数据,主要问题代码如下: #! /usr/bin/expect while {true} { set timeout 60 spawn ...
- Java中的监听器
servlet的技术规范包括三个:servlet,listener,filter,今天记录一下listener的学习. 监听器就是监听某个对象的状态变化的技术.监听器包括事件源,监听器,注册监听器以及 ...
- 为什么我不再用 .NET 框架(网摘)
觉得好就拿过来收藏了,保留出处链接-凌风 2017年08月23日 14:51:32 hisense_大致若愚 阅读数:9355 .NET平台很棒.真的很棒.直到它不再那么棒.我为什么不再用.NET?简 ...
- Nested Loops,Hash Join 和 Sort Merge Join. 三种不同连接的不同:
原文:https://blog.csdn.net/tianlesoftware/article/details/5826546 Nested Loops,Hash Join 和 Sort Merge ...
- 表格中的td内的div的文字内容禁止换行一行显示的css
td { white-space: nowrap } td div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; ...
- 《Python高性能编程》——列表、元组、集合、字典特性及创建过程
这里的内容仅仅是本人阅读<Python高性能编程>后总结的一些知识,用于自己更好的了解Python机制.本人现在并不从事计算密集型工作:人工智能.数据分析等.仅仅只是出于好奇而去阅读这本书 ...
- 如何通过github上传项目并在readme.md中展示图片二维码
将本地项目上传至github 第一步:git init (创建仓库) 第二步:git add README.md (添加项目)git add * 第三步:git commit -m &qu ...
- 【七】ab压测
[任务7]ab压测 安装ab压测软件 命令:yum -y install httpd-tools 进行压力测试: 执行命令:ab -c 20 -n 5000 http://192.168.159.30 ...
- 用GO写一个后台权限管理系统
最近用GO写了一个后台权限管理系统,在WIN10和ubuntu下部署,在win系统下编译ububtu的部署文件要先做如下配置 set GOARCH=amd64 set GOOS=linux go bu ...
- [Java算法分析与设计]--链式堆栈的设计
在上篇文章当中,我们实现了底层为数组的顺序栈.在我之前的文章中也提到过:以数组为数据结构基础在存储数据方面需要一整块连续的内存来存放数据,一旦遇到需要可以动态扩展的功能需求时如果数据量大可能会给虚拟机 ...