Advertisement
steve-shambles-2109

167-Rotatary scale in Tkinter

Oct 15th, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. """
  2. Python code snippets vol 34:
  3. 167-Rotatary scale in Tkinter
  4. stevepython.wordpress.com
  5.  
  6. pip3 install tk_tools
  7.  
  8. Tested on: Win 7\Linux Mint 19.1
  9.  
  10. Source:
  11. https://github.com/slightlynybbled/tk_tools/blob/master/examples/rotary_scale.py
  12. """
  13.  
  14. import tkinter as tk
  15. import tk_tools
  16.  
  17. from tk_tools.images import rotary_gauge_volt
  18.  
  19. max_value = 100.0
  20. min_value = 0.0
  21.  
  22.  
  23. def increment():
  24.     global value
  25.  
  26.     value += increment_value
  27.     if value > max_value:
  28.         value = max_value
  29.  
  30.     p1.set_value(value)
  31.     p2.set_value(value)
  32.  
  33.  
  34. def decrement():
  35.     global value
  36.     value -= increment_value
  37.  
  38.     if value < min_value:
  39.         value = min_value
  40.  
  41.     p1.set_value(value)
  42.     p2.set_value(value)
  43.  
  44.  
  45. if __name__ == '__main__':
  46.  
  47.     root = tk.Tk()
  48.  
  49.     p1 = tk_tools.RotaryScale(root, max_value=max_value, size=100, unit='km/h')
  50.     p1.grid(row=0, column=0)
  51.  
  52.     p2 = tk_tools.RotaryScale(root,
  53.                               max_value=max_value,
  54.                               size=100,
  55.                               needle_thickness=3,
  56.                               needle_color='white',
  57.                               img_data=rotary_gauge_volt)
  58.  
  59.     p2.grid(row=0, column=1)
  60.  
  61.     increment_value = 1.0
  62.     value = 0.0
  63.  
  64.     inc_btn = tk.Button(root,
  65.                         text='increment_value by {}'.format(increment_value),
  66.                         command=increment)
  67.  
  68.     inc_btn.grid(row=1, column=0, columnspan=2, sticky='news')
  69.  
  70.     dec_btn = tk.Button(root,
  71.                         text='decrement by {}'.format(increment_value),
  72.                         command=decrement)
  73.  
  74.     dec_btn.grid(row=2, column=0, columnspan=2, sticky='news')
  75.  
  76.     root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement