Issue
The following code lets me print out the selected value from the Combobox, but I need to print (get) the index number of selected item in the list. How can I do that?
import Tkinter
import tkMessageBox
from Tkinter import *
import ttk
from ttk import *
app = Tk()
def OptionCallBack(*args):
print variable.get()
variable = StringVar(app)
variable.set("Select From List")
variable.trace('w', OptionCallBack)
so = ttk.Combobox(app, textvariable=variable)
so.config(values =('Tracing Upstream', 'Tracing Downstream','Find Path'))
so.grid(row=1, column=4, sticky='E', padx=10)
app.mainloop()
Solution
Use the current
method on the combobox.
import Tkinter
import tkMessageBox
from Tkinter import *
import ttk
from ttk import *
app = Tk()
def OptionCallBack(*args):
print variable.get()
print so.current()
variable = StringVar(app)
variable.set("Select From List")
variable.trace('w', OptionCallBack)
so = ttk.Combobox(app, textvariable=variable)
so.config(values =('Tracing Upstream', 'Tracing Downstream','Find Path'))
so.grid(row=1, column=4, sticky='E', padx=10)
app.mainloop()
Answered By - Khristos
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.