以下是一个示例代码,当按下按钮时播放闪光动画:
import tkinter as tk
def play_animation():
# 播放闪光动画的代码在这里
print("播放闪光动画")
def button_clicked():
play_animation()
root = tk.Tk()
button = tk.Button(root, text="按下按钮", command=button_clicked)
button.pack()
root.mainloop()
上述示例使用了tkinter库创建了一个GUI窗口,并在窗口中添加了一个按钮。当按钮被点击时,触发button_clicked()
函数,该函数又会调用play_animation()
函数来播放闪光动画。在示例中,我们只是简单地使用print()
语句来模拟闪光动画的播放,你可以根据具体需求替换这部分代码来实现实际的闪光动画效果。
上一篇:按下按钮让线程开始工作