(Sorry, I've missed the code, here is the proper post:)
Hi,
how can I convert the selected item from Listbox and convert into integer for using in my code?
Here is the code:---------------------------------------------------------------------------------------------
from tkinter import*
root=Tk()
sizex = 600
sizey = 400
posx = 40
posy = 20
root.wm_geometry("%dx%d+%d+%d" % (sizex, sizey, posx, posy))
def Select(a):
a = int(mylistbox.get(ANCHOR))
if a == 1:
a = 2
return(a)
elif a == 2:
a = 3
return(a)
mylistbox=Listbox(root,height=2, width=25, font=('times',13))
mylistbox.bind('<<ListboxSelect>>',Select)
#mylistbox.insert(1,2)
itemsforlistbox=['1','2']
mylistbox.place(x=32,y=90)
scroll = Scrollbar(root, orient=VERTICAL) # the allignment of the scrollbar
mylistbox["yscrollcommand"]=scroll.set # link the list with the scroll
scroll["command"]=mylistbox.yview # link the scroll with the scroll
mylistbox.grid(row=5, column=5)
scroll.grid(row=5, column=5, sticky=N+S+E)
for items in itemsforlistbox:
mylistbox.insert(END,items)
root.mainloop()
-----------------------------------------------------------------------------------------------------------------------------------
I already converted the item into an integer and I can return it with a new value, but how can I use this value in my code? I've tried anything I can imagine, for example I used the variable b, but I always get an error:
---------------------------------------------------------------------------------------------------------------------------------------
from tkinter import*
root=Tk()
sizex = 600
sizey = 400
posx = 40
posy = 20
root.wm_geometry("%dx%d+%d+%d" % (sizex, sizey, posx, posy))
def Select(a):
a = int(mylistbox.get(ANCHOR))
if a == 1:
a = 2
return(a)
elif a == 2:
a = 3
return(a)
b = Select(a) + 2
mylistbox=Listbox(root,height=2, width=25, font=('times',13))
mylistbox.bind('<<ListboxSelect>>',Select)
#mylistbox.insert(1,2)
itemsforlistbox=['1','2']
mylistbox.place(x=32,y=90)
scroll = Scrollbar(root, orient=VERTICAL) # the allignment of the scrollbar
mylistbox["yscrollcommand"]=scroll.set # link the list with the scroll
scroll["command"]=mylistbox.yview # link the scroll with the scroll
mylistbox.grid(row=5, column=5)
scroll.grid(row=5, column=5, sticky=N+S+E)
for items in itemsforlistbox:
mylistbox.insert(END,items)
root.mainloop()