2022-04-10课件
2022-04-10 08:23:05    16    0    0
python-w73

控件通用方法

after方法

定时任务, 让控件在 delay_ms 毫秒后去调用函数 func , 其中 args 为函数的参数

格式为:

  1. w.after(delay_ms, func=None, *args)

方法返回值为int类型的标识符, 可以使用 .after_cancel() 方法取消定时任务

bind方法

向控件添加一个事件绑定

格式为:

  1. w.bind(sequence=None, func=None, add=None)

参数 sequence 指的是事件名, func 是回调函数, 当该事件已经绑定到一个回调函数上, 默认情况会使用新函数覆盖老函数, 使 用 add=’+’ 保留新旧两个

事件格式: <[modifier-]…type[-detail]>

title

事件名如何表示:

  • 鼠标事件:
    Button: 代表所有鼠标键的点击
    Button-1: 代表鼠标左键的点击
    Button-2/3: 代表鼠标右键的点击
    ButtonPress: 鼠标按下事件
    ButtonPress-1: 代表鼠标左键的点击
    ButtonPress-2/3: 代表鼠标右键的点击
    ButtonRelease: 鼠标抬起事件
    ButtonRelease-1: 代表鼠标左键的点击
    ButtonRelease-2/3: 代表鼠标右键的点击
  • 按键事件:
    KeyPress: 按键按下
    KeyRelease: 按键抬起
    KeyPress-a: 按字母按下事件, 区分大小写
    Control-Shift-KeyPress-H: 组合键
    KeyPress-Return: 回车键Enter

函数格式:

  1. def 函数名(事件参数)

如:

  1. def func_bind(event):
  2. print("mouse clicked")

Pre: 2022-04-10课后作业

Next: 2022-03-27课堂代码

16
Sign in to leave a comment.
No Leanote account? Sign up now.
0 comments
Table of content