I have found the following program on the internet but it is a Python 2 program.
I realise that Tkinter needs changing to tkinter but it then fails on the next line, with an error regarding no module called ttk
I would appreciate help to find a Python 3 alternative to ttk.
Code: Select all
# This is a Python 2 program
from Tkinter import *
import Tkinter as ttk
from ttk import *
root = Tk()
root.title("Tk Drop Down Menu")
# 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 = [ '1,000','2,000','3,000','4,000','5,000','10,000','15,000']
tkvar.set('10,000') # set the default option
popupMenu = OptionMenu(mainframe, tkvar, choices[1], *choices)
Label(mainframe, text="Choose an Option").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()