Python课程-w73班
Louyj's Blog
Toggle navigation
Python课程-w73班
Home
班级课件
课堂代码
课后作业
学习资料
Archives
Tags
2022-04-10课堂代码
2022-04-10 08:28:32
18
0
0
python-w73
``` import string import tkinter from tkinter import ttk import random as r window = tkinter.Tk() window.title("随机密码生成器") ''' gui 事件驱动 1. 根据用户的操作去进行响应的处理 2. 定时器, after, 在多少时间之后触发一个函数的回调, 格式: win.after(delay_ms,func=函数,*args), 只会执行一次 3. 事件绑定, bind, 专门将事件和一个函数进行绑定, 格式: win.bind(sequence=<事件名>,func=函数) 3.1 按键: 键盘敲击某个按键去调用一个函数 3.2 鼠标: 鼠标按某个键(左/右/中)去调用一个函数 事件名如何表示: - 鼠标事件: 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 函数: bind函数有固定格式, 一个参数event ''' def func01(): print("after function") window.after(100, func=func01) # window.after(5000, func=func01) def func_bind(event): print("mouse clicked") window.bind(sequence="<KeyPress-Return>", func=func_bind) window.mainloop() ```
Pre:
2022-05-08课件
Next:
2022-04-10课后作业
0
likes
18
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Submit
Sign in
to leave a comment.
No Leanote account?
Sign up now.
0
comments
More...
Table of content
No Leanote account? Sign up now.