Advertisement
here2share

# arc_rpm.py

Nov 16th, 2022
749
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. # arc_rpm.py
  2.  
  3. import tkinter as tk
  4. import math
  5. root = tk.Tk()
  6. width,height=410,310 # set the variables
  7. d=str(width)+"x"+str(height+40)
  8. root.geometry(d)
  9. canvas = tk.Canvas(root, width=width-10, height=height-50,bg='#FFFFFF')
  10. canvas.grid(row=0,column=0)
  11. arc_w=50 # width of the arc
  12. x1,y1,x2,y2=35,35,355,355 # dimensions for the arc
  13. x,y,r=195,195,150
  14.  
  15. canvas.create_arc(x1, y1,x2,y2, start=0, extent=20,outline='red',
  16.          width=arc_w,style=tk.ARC)
  17. canvas.create_arc(x1, y1,x2,y2, start=20, extent=30,outline='orange',
  18.         width=arc_w,style=tk.ARC)
  19. canvas.create_arc(x1, y1,x2,y2, start=50, extent=40,outline='yellow',
  20.         width=arc_w,style=tk.ARC)
  21. canvas.create_arc(x1, y1,x2,y2, start=90, extent=90,outline='green',
  22.         width=arc_w,style=tk.ARC)
  23.        
  24. # small circle at center
  25. canvas.create_oval(x-10,y-10,x+10,y+10,fill='dark gray',width=0)
  26. in_radian=math.radians(180) # getting radian value
  27.  
  28. def draw_line(in_radian):
  29.     return canvas.create_line(x,y,(x+r*math.cos(in_radian)),
  30.             (y-r*math.sin(in_radian)),width=6)
  31.  
  32. def my_upd(value):
  33.     global line
  34.     in_radian = math.pi - math.radians(my_scale.get()) # scale value in radian
  35.     canvas.delete(line) # delete the pointer
  36.     line = draw_line(in_radian)
  37. line = draw_line(in_radian)
  38.  
  39. my_scale = tk.Scale(root, from_=0, to=180, orient='horizontal',
  40.  length=395,command= my_upd)
  41. my_scale.grid(row=2,column=0)
  42. root.mainloop()
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement