gui3.py 802 B

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