récupération valeur Listebox tkinter
Bonjour à tous
Dans mon apprentissage pour python j'essaie de récupérer une valeur d'une List box en double clique dessus
La ListeBox est dans un Def,
le print() récupère bien la valeur mais la valeur de retour (return) est toujours None…. Et je ne comprends pas pourquoi
Merci pour votre aide
Code:
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| from tkinter import *
def choix_tkinter ():
root=Tk()
sizex = 600
sizey = 400
posx = 40
posy = 20
root.wm_geometry("%dx%d+%d+%d" % (sizex, sizey, posx, posy))
itemsforlistbox=['one','two','three','four','five','six','seven']
selected_item = StringVar()
def CurSeletList1(evt):
value=str(mylistbox.get(mylistbox.curselection()))
print(value)
root.destroy()
return valu
def CurSeletList2(evt):
value=str(mylistbox2.get(mylistbox2.curselection()))
root.destroy()
print(value)
return value
def nondispo():
print("non dispo")
root.destroy()
mylistbox=Listbox(root,width=20,height=10,font=('times',13))
mylistbox.bind('<Double-Button>',CurSeletList1)
mylistbox.pack(side="right")
mylistbox2=Listbox(root,width=20,height=10,font=('times',13))
mylistbox2.bind('<Double-Button>',CurSeletList2)
mylistbox2.pack(side="left")
for items in itemsforlistbox:
mylistbox.insert(END,items)
for items in itemsforlistbox:
mylistbox2.insert(END,items)
BUT_Quitter = Button (root , text = "Quitter" , command =nondispo)
BUT_Quitter.pack(side=BOTTOM,fill = BOTH)
root.mainloop()
choix = choix_tkinter ()
print(choix) |