Tkinter: How to create choice box

Nefritox picture Nefritox · Mar 6, 2015 · Viewed 10.5k times · Source

I need to create a choice box
choice box
where i can click on arrow and it give me list of choices.
choice box pic 2
And if i click on one of them it will change it in that first rectangle.
Its possible to do something like this? Thank you for any idea.

Answer

Malik Brahimi picture Malik Brahimi · Mar 6, 2015

You can also try an OptionMenu:

from Tkinter import *

root = Tk()

choices = ['GB', 'MB', 'KB']
variable = StringVar(root)
variable.set('GB')

w = OptionMenu(root, variable, *choices)
w.pack(); root.mainloop()

OptionMenu example

Or you can try using a Combobox:

from ttk import *
from Tkinter import *

root = Tk()

choices = ['GB', 'MB', 'KB']
variable = StringVar(root)
variable.set('GB')

w = Combobox(root, values = choices)
w.pack(); root.mainloop()

Combobox example