Making a dropdown menu for a python Pass program I am making for school

55 Views Asked by At

I'm a freshman in high school. I am making a Pass program for my school and I'm not sure how to store our staff directory in a file and put it in a dropdown menu when selecting the person the pass is being sent to for the GUI tkinter.

Here's my code so far:

# the visuals, text labels, buttons to show
Label(frame, text="Send a Pass", bg="#B80C09", fg="#01BAEF", font="Helvetica 40 bold").pack(pady=5)

Label(frame, text="From:", bg="#B80C09", fg="#FBFBFF", font="Helvetica 15 bold").pack()

self.pass_from = Entry(frame, textvariable=_passfrom, width=50, font="Helvetica 15 bold").pack(pady=5, ipady=5)

Label(frame, text="To:", bg="#B80C09", fg="#FBFBFF", font="Helvetica 15 bold").pack()

self.pass_to = Entry(frame, textvariable=_passto, width=50, font="Helvetica 15 bold").pack(pady=5, ipady=5)

Label(frame, text="For:", bg="#B80C09", fg="#FBFBFF", font="Helvetica 15 bold").pack()

self.pass_for = Entry(frame, textvariable=_passfor, width=50, font="Helvetica 15 bold").pack(pady=5, ipady=5)

self.submit_button = Button(frame, text="Submit", font="Helvetica 15 bold", borderwidth="0", bg="#0B4F6C", fg="#FBFBFF", command=submit_pass_clicked).pack(pady=10, ipadx=10, ipady=10)

"pass_to" is the one I'm trying to make a dropdown menu. It's currently just an Entry widget. I want to be able to click on it and have a dropdown menu with the staff directory in it. Help?

1

There are 1 best solutions below

0
On

Use OptionMenu. Following this tutorial:

https://pythonspot.com/tk-dropdown-example/

choices = ['Mrs Fish', 'Mr Octopus']
_passto.set('Mr Octopus')
self.pass_to = OptionMenu(frame, _passto, *choices, width=50, font="Helvetica 15 bold").pack(pady=5, ipady=5)