Advertisement
here2share

# Tk_slider_shuttle.py

Dec 26th, 2021
1,547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. # Tk_slider_shuttle.py
  2.  
  3. from tkinter import *
  4.  
  5. root = Tk()
  6.  
  7. root.title("Tk_slider_shuttle")
  8. root.geometry("160x600+10+10")
  9.  
  10. speed = [-1000,-100,-10,-5,-1]
  11. speed += [0]+list(map(abs, speed[::-1]))
  12. speed = speed[::-1]
  13.  
  14. label = Label(root, text="Slider Shuttle")
  15. label.pack(anchor="w", padx=10, pady=10)
  16. shuttle_slide = Scale(root, from_=0, to=10, length=500, tickinterval=1, variable=5, orient=VERTICAL)
  17. shuttle_slide.pack(anchor='w', padx=0, pady=20)
  18. shuttle_slide.val = 0
  19. shuttle_slide.active = 0
  20. shuttle_slide.set(5)
  21. frame = Frame(root, width=36, height=500)
  22. frame.place(x=1, y=62)
  23. incr = 46.9
  24.  
  25. for i in range(0,11):
  26.     t = Label(root, text=speed[i])
  27.     t.place(x=56, y=i*incr+68)
  28.  
  29. val = Label(root, font=("Arial", 18), text=0, fg='blue')
  30. val.place(x=80, y=30)
  31.  
  32. def on_press(e):
  33.     shuttle_slide.active = 1
  34.  
  35. def on_release(e):
  36.     shuttle_slide.active = 0
  37.     shuttle_slide.set(5)
  38.  
  39. root.bind("<ButtonRelease-1>", on_release)
  40. root.bind("<Button-1>", on_press)
  41.  
  42. def main():
  43.     if shuttle_slide.active:
  44.         t = shuttle_slide.get()
  45.         if speed[t]:
  46.             shuttle_slide.val += speed[t]
  47.             shuttle_slide.val = max(-9999, min(9999, shuttle_slide.val))
  48.             val.config(text=shuttle_slide.val)
  49.     root.after(400, main)  
  50.  
  51. main()
  52.  
  53. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement