Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. from tkinter import *
  2. import tkinter as ttk
  3.  
  4. root = Tk()
  5. root.title("Tk dropdown example")
  6.  
  7. # Add a grid
  8. mainframe = Frame(root)
  9. mainframe.grid(column=0,row=0, sticky=(N,W,E,S) )
  10. mainframe.columnconfigure(0, weight = 1)
  11. mainframe.rowconfigure(0, weight = 1)
  12. mainframe.pack(pady = 100, padx = 100)
  13.  
  14. # Create a Tkinter variable
  15. tkvar = StringVar(root)
  16.  
  17. # Dictionary with options
  18. choices = { 'prntScr','imgur'}
  19. tkvar.set('imgur') # set the default option
  20.  
  21. popupMenu = OptionMenu(mainframe, tkvar, *choices)
  22. Label(mainframe, text="Choose the image service").grid(row = 1, column = 1)
  23. popupMenu.grid(row = 2, column =1)
  24.  
  25. # on change dropdown value
  26. def change_dropdown(*args):
  27. print( tkvar.get() )
  28.  
  29. # link function to change dropdown
  30. tkvar.trace('w', change_dropdown)
  31.  
  32. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement