-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTutorial-16-Dropdown-Menus.py
More file actions
30 lines (22 loc) · 1.09 KB
/
Tutorial-16-Dropdown-Menus.py
File metadata and controls
30 lines (22 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from doctest import OPTIONFLAGS_BY_NAME
from tkinter import *
root=Tk()
root.title("Creating the dropdown menus")
root.iconbitmap("images/ericsson-blue-e.ico")
root.geometry("480x240")
# drop down boxes
def show():
Label(root,text=clicked.get()).pack()
"""
# we can add all the menu options for the dropdown menu
clicked=StringVar()
clicked.set("Select an option") # gives default value to the dropdown menu
drop=OptionMenu(root,clicked,"Select an option","Monday","Tuesday","Thursday","Friday","Saturday").pack()
"""
# we can also make the options in the option menu to be a list to make the code easy to read and convinient to edit
options_available=["Monday","Tuesday","Thursday","Friday","Saturday"]
clicked=StringVar()
clicked.set("Select an option") # gives default value to the dropdown menu
drop=OptionMenu(root,clicked,*options_available).pack() # without the star in fromt of options_available list will not work as the intended way and will give the tuple of all the items in the list
button=Button(root,text="Click me to show the chose option",command=show).pack()
root.mainloop()