Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- import tkinter as ttk
- root = Tk()
- root.title("Tk dropdown example")
- # 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 = 100, padx = 100)
- # Create a Tkinter variable
- tkvar = StringVar(root)
- # Dictionary with options
- choices = { 'prntScr','imgur'}
- tkvar.set('imgur') # set the default option
- popupMenu = OptionMenu(mainframe, tkvar, *choices)
- Label(mainframe, text="Choose the image service").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