Advertisement
steve-shambles-2109

Tkinter smart option menu

Oct 18th, 2019
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. """
  2. Python code snippets vol 35:
  3. 175-Tkinter smart option menu
  4. stevepython.wordpress.com
  5.  
  6. pip3 install tk_tools
  7.  
  8. source:
  9. https://github.com/slightlynybbled/tk_tools/blob/master/examples/smart_optionmenu.py
  10. """
  11.  
  12. import tkinter as tk
  13. import tk_tools
  14.  
  15.  
  16. if __name__ == '__main__':
  17.     root = tk.Tk()
  18.  
  19.     tk.Label(root, text="The variable value: ").grid(row=1, column=0, sticky='ew')
  20.     value_label = tk.Label(root, text="")
  21.     value_label.grid(row=1, column=1, sticky='ew')
  22.  
  23.     def callback(value):
  24.         value_label.config(text=str(value))
  25.  
  26.     tk.Label(root, text="Select a value: ").grid(row=0, column=0, sticky='ew')
  27.     drop_down = tk_tools.SmartOptionMenu(root, ['one', 'two', 'three'], callback=callback)
  28.     drop_down.grid(row=0, column=1, sticky='ew')
  29.  
  30.     root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement