ich würde gerne ein Drop-Down Menu erstellen, mit der Eigenschaft, dass man das ausgewählte Objekt "weiterverarbeiten" kann.
Das ist mein bisheriger Code:
Code: Alles auswählen
from tkinter import *
ws = Tk()
ws.geometry('400x300')
def selection(choice):
choice = variable.get()
print(choice)
countries = ['Bahamas','Canada', 'Cuba']
# setting variable for Integers
variable = StringVar()
variable.set("decide")
# creating widget
dropdown = OptionMenu(
ws,
variable,
*countries,
command=selection
)
# positioning widget
dropdown.pack(expand=True)
# infinite loop
ws.mainloop()
Dafür hatte ich überlegt, ob man die Variable "choice" mit return aus der Funktion rausholt. Oder eventuell eine globale Variable definiert.
Dabei wird jedoch ganz zu Beginn eine frühere Variable ausgegeben...
Code: Alles auswählen
from tkinter import *
ws = Tk()
ws.geometry('400x300')
def selection(choice):
choice2 = variable.get()
print(choice2)
return (choice2)
countries = ['Bahamas','Canada', 'Cuba']
# setting variable for Integers
variable = StringVar()
variable.set("decide")
# creating widget
dropdown = OptionMenu(
ws,
variable,
*countries,
command=selection
)
# positioning widget
dropdown.pack(expand=True)
print(choice2)
# infinite loop
ws.mainloop()
Ich hoffe, dass mir jemand meine Verwirrung nehmen kann...
Viele Grüße