CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day10/gui3.py
Views: 729
1
"""
2
3
使用tkinter创建GUI
4
- 在窗口上制作动画
5
6
Version: 0.1
7
Author: 骆昊
8
Date: 2018-03-14
9
10
"""
11
12
import tkinter
13
import time
14
15
16
# 播放动画效果的函数
17
def play_animation():
18
canvas.move(oval, 2, 2)
19
canvas.update()
20
top.after(50, play_animation)
21
22
23
x = 10
24
y = 10
25
top = tkinter.Tk()
26
top.geometry('600x600')
27
top.title('动画效果')
28
top.resizable(False, False)
29
top.wm_attributes('-topmost', 1)
30
canvas = tkinter.Canvas(top, width=600, height=600, bd=0, highlightthickness=0)
31
canvas.create_rectangle(0, 0, 600, 600, fill='gray')
32
oval = canvas.create_oval(10, 10, 60, 60, fill='red')
33
canvas.pack()
34
top.update()
35
play_animation()
36
tkinter.mainloop()
37
38
# 请思考如何让小球碰到屏幕的边界就弹回
39
# 请思考如何用面向对象的编程思想对上面的代码进行封装
40
41