Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # arc_rpm.py
- import tkinter as tk
- import math
- root = tk.Tk()
- width,height=410,310 # set the variables
- d=str(width)+"x"+str(height+40)
- root.geometry(d)
- canvas = tk.Canvas(root, width=width-10, height=height-50,bg='#FFFFFF')
- canvas.grid(row=0,column=0)
- arc_w=50 # width of the arc
- x1,y1,x2,y2=35,35,355,355 # dimensions for the arc
- x,y,r=195,195,150
- canvas.create_arc(x1, y1,x2,y2, start=0, extent=20,outline='red',
- width=arc_w,style=tk.ARC)
- canvas.create_arc(x1, y1,x2,y2, start=20, extent=30,outline='orange',
- width=arc_w,style=tk.ARC)
- canvas.create_arc(x1, y1,x2,y2, start=50, extent=40,outline='yellow',
- width=arc_w,style=tk.ARC)
- canvas.create_arc(x1, y1,x2,y2, start=90, extent=90,outline='green',
- width=arc_w,style=tk.ARC)
- # small circle at center
- canvas.create_oval(x-10,y-10,x+10,y+10,fill='dark gray',width=0)
- in_radian=math.radians(180) # getting radian value
- def draw_line(in_radian):
- return canvas.create_line(x,y,(x+r*math.cos(in_radian)),
- (y-r*math.sin(in_radian)),width=6)
- def my_upd(value):
- global line
- in_radian = math.pi - math.radians(my_scale.get()) # scale value in radian
- canvas.delete(line) # delete the pointer
- line = draw_line(in_radian)
- line = draw_line(in_radian)
- my_scale = tk.Scale(root, from_=0, to=180, orient='horizontal',
- length=395,command= my_upd)
- my_scale.grid(row=2,column=0)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement