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的更多相关文章

  1. Python Tkinter基础控件入门实例

    分享一个Python Tkinter基础控件用法的入门例子,包括窗口的显示.显示内置图片.弹出窗口.菜单等. 例子,Python Tkinter基础控件的用法 # -*- coding: utf-8 ...

  2. Python Tkinter 学习成果:点歌软件music

    笔者工作业余时间也没什么爱好,社交圈子也小,主要娱乐就是背着自己带电瓶的卖唱音响到住地附近找个人多的位置唱唱KtV. 硬件上点歌就用笔记本电脑,歌曲都是网上下载的mkv格式的含有两个音轨的视频.因此点 ...

  3. Python Tkinter Entry(文本框)

    Python学习记录--关于Tkinter Entry(文本框)的选项.方法说明,以及一些示例. 属性(Options) background(bg) borderwidth(bd) cursor e ...

  4. python tkinter Listbox用法

    python tkinter组件的Listbox的用法,见下面代码的演示: from tkinter import * root=Tk() v=StringVar() #Listbox与变量绑定' l ...

  5. python Tkinter之Button

    Button小部件是一个标准的Tkinter的部件,用于实现各种按钮.按钮可以包含文本或图像,您可以调用Python函数或方法用于每个按钮. Tkinter的按钮被按下时,会自动调用该函数或方法. 该 ...

  6. python gui tkinter快速入门教程 | python tkinter tutorial

    本文首发于个人博客https://kezunlin.me/post/d5c57f56/,欢迎阅读最新内容! python tkinter tutorial Guide main ui messageb ...

  7. Python tkinter模块弹出窗口及传值回到主窗口操作详解

    这篇文章主要介绍了Python tkinter模块弹出窗口及传值回到主窗口操作,结合实例形式分析了Python使用tkinter模块实现的弹出窗口及参数传递相关操作技巧,需要的朋友可以参考下 本文实例 ...

  8. Python Tkinter 文本框(Entry)

    Python Tkinter 文本框用来让用户输入一行文本字符串. 你如果需要输入多行文本,可以使用 Text 组件. 你如果需要显示一行或多行文本且不允许用户修改,你可以使用 Label 组件. 语 ...

  9. Python Tkinter 窗口创建与布局

    做界面,首先需要创建一个窗口,Python Tkinter创建窗口很简单:(注意,Tkinter的包名因Python的版本不同存在差异,有两种:Tkinter和tkinter,读者若发现程序不能运行, ...

  10. Python tkinter 实现简单登陆注册 基于B/S三层体系结构,实现用户身份验证

    Python tkinter 实现简单登陆注册 最终效果 开始界面 ​ 注册 登陆 ​ 源码 login.py # encoding=utf-8 from tkinter import * from ...

随机推荐

  1. Linux-- 查看文件 more与其它

    more 翻页查看 用法:more 文件名 nl 显示行号打印(不常用) 1.不打印空白行行号:nl -b t 文件名 类似 cat -b 文件名 2.打印所有行行号:nl -b a 文件名 类似 c ...

  2. mac 下安装php7.1 redis

    1.下载phpredis源文件 https://nodeload.github.com/nicolasff/phpredis/zip/master 下载后解压 2.执行命令 phpize  执行后执行 ...

  3. 使用Mybatis连接到Mysql报错,WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be esta

    在Eclipse中使用springboot整合Mybatis,连接到5.7版本Mysql报错WARN: Establishing SSL connection without server's ide ...

  4. Mariadb相关

    centos下Mariadb相关 MariaDB 是一个采用 Maria 存储引擎的MySQL分支版本,是由原来 MySQL 的作者Michael Widenius创办的公司所开发的免费开源的数据库服 ...

  5. 利用.htaccess文件将多个子域名解析至对应的子目录

    对于不支持子域名解析但是支持 .htaccess 的主机来说,这个功能就非常有用了 假设有主域名 ppios.com,子域名 yspx.ppios.com 和 ask.ppios.com,设置结果为访 ...

  6. 关于pythond在终端中运行

    下载python并安装后,如果想要在终端中直接运行,我们需要配置环境变量. 在计算机右击选择属性,,选择高级属性,点击环境变量,,即可新建环境变量, ,然后可以在终端中运行python解释器.

  7. PTA(BasicLevel)-1012 数字分类

    一 题目描述    给定一系列正整数,请按要求对数字进行分类,并输出以下 5 个数字: ​​ = 能被 5 整除的数字中所有偶数的和: ​​ = 将被 5 除后余 1 的数字按给出顺序进行交错求和,即 ...

  8. UVA 400 - Unix ls (Unixls命令)

    csdn : https://blog.csdn.net/su_cicada/article/details/86773007 例题5-8 Unixls命令(Unix ls,UVa400) 输入正整数 ...

  9. CentOS7和OpenStack的笔记(一)

    CentOS7和OpenStack的笔记(一) 最近搞CentOS7系统和OpenStack框架,整了近一个星期,系统装了好几次,框架搭了又从搭.虽然最后的实例没能启动成功,但是在这专研的一个星期里, ...

  10. QPushButton槽函数触发两次的问题

    以前经常使用qt creator界面管理直接跳转到槽函数没发现这个问题,今天手动写了个槽函数发现按键会触发两次.根据网上的说法是按键会自动连接一个槽函数,如果我们手动添加的槽函数命名规则符合槽函数的命 ...