I'm trying to return a value after having selected it with Tkinter, but I keep getting PY_VAR0
.
I have checked on the internet but the solution is to use .get()
, which I have already done.
Does someone have an idea please?
from tkinter import *
def f1():
fenetre1 = Tk()
fenetre1.title("Ma fenetre") # titre de la fenêtre
texte3 = Label(fenetre1, text='Nombre de cases par ligne/colonne :')
texte3.pack()
listeoptions = []
for i in range(10, 21):
listeoptions.append(i)
v = StringVar(fenetre1)
v.set(listeoptions[0])
w = OptionMenu(fenetre1, v, *listeoptions)
w.pack()
def ok():
v.get()
print(v)
button = Button(fenetre1, text="Jouer", command=ok)
button.pack(side=BOTTOM)
fenetre1.mainloop()
f1()
You are correct that the solution is to use .get()
. However, you are currently not doing anything with the value returned by this method. Try printing it instead:
def ok():
print(v.get())