fork download
  1. import tkinter, math
  2.  
  3. def move():
  4. global x
  5. global y
  6. global vy
  7. global t
  8.  
  9. canvas.delete('ball')
  10. canvas.create_oval(x-MARGIN, (HEIGHT-y)-MARGIN, x+MARGIN, (HEIGHT-y)+MARGIN, fill='red', tags='ball')
  11.  
  12. for i in range(1, 60):
  13. canvas.create_line(0, i * 10, 800, i * 10,
  14. fill = '#000000' if i == 30 else '#d2d2d2')
  15. for i in range(1, 80):
  16. canvas.create_line(i * 10, 0, i * 10, 600,
  17. fill = '#000000' if i == 1 else '#d2d2d2')
  18. if i > 1 and (i - 1) % 5 == 0:
  19. canvas.create_text(i * 10, 310, text = f'{(i - 1) * 10}')
  20.  
  21.  
  22. if 0 <= x and x <= WIDTH and 0 <= y and y <= HEIGHT:
  23. x = x + vx0 * dt
  24. v1 = vy
  25. v2 = vy - g * dt
  26. y = y + (v1+ v2) / 2.0 * dt
  27. vy = v2
  28. t = t + dt
  29. else:
  30. x = x0
  31. y = y0
  32. vy = vy0
  33. t = t0
  34.  
  35. window.after(50, move)
  36.  
  37.  
  38. #WIDTH, HEIGHT = 1000, 500
  39. WIDTH, HEIGHT = 800, 600
  40. MARGIN = 10
  41.  
  42. t0 = 0.0
  43. dt = 0.1
  44. g = 9.8
  45.  
  46. v0 = float(input('初速度を入力してください'))
  47. degrees = float(input('角度を入力してください'))
  48.  
  49. theta = degrees * math.pi / 180
  50. vx0 = v0 * math.cos(theta)
  51. vy0 = v0 * math.sin(theta)
  52. x0 = 0
  53. y0 = 3 * HEIGHT / 4
  54. x = x0
  55. y = y0
  56. vy = vy0
  57. t = t0
  58.  
  59. geo_str = str(WIDTH+MARGIN*2) + 'x' + str(HEIGHT+MARGIN*2)
  60. window = tkinter.Tk()
  61. window.geometry(geo_str)
  62. window.title('moving')
  63.  
  64. canvas = tkinter.Canvas(window, width=WIDTH, height=HEIGHT, bg='white')
  65. canvas.place(x=MARGIN, y=MARGIN)
  66. # move 内に定義してるんでここは重複してる。
  67. ##canvas.create_oval(x-MARGIN, (HEIGHT-y)-MARGIN, x+MARGIN, (HEIGHT-y)+MARGIN, fill='red', tags='ball')
  68.  
  69. move()
  70. window.mainloop()
  71.  
Runtime error #stdin #stdout #stderr 0.15s 25768KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 1, in <module>
ModuleNotFoundError: No module named 'tkinter'