Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_optionmenu.py
- from Tkinter import *
- root = Tk()
- root.title("Tk OptionMenu")
- # Add a grid
- mainframe = Frame(root)
- mainframe.grid(column=0,row=0, sticky=(N,W,E,S))
- mainframe.columnconfigure(0, weight = 1)
- mainframe.rowconfigure(0, weight = 1)
- mainframe.pack(pady = 50, padx = 50)
- # Create a Tkinter variable
- tkvar = StringVar(root)
- # Dictionary with options
- choices = { 'Pizza','Lasagne','Fries','Salad','Cheeseburger'}
- tkvar.set('Fries') # set the default option
- popupMenu = OptionMenu(mainframe, tkvar, *choices)
- Label(mainframe, text="Choose A Dish").grid(row = 1, column = 1)
- popupMenu.grid(row = 2, column =1)
- # on change dropdown value
- def change_dropdown(*args):
- print( tkvar.get() )
- # link function to change dropdown
- tkvar.trace('w', change_dropdown)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement