Connecting Tech Pros Worldwide Forums | Help | Site Map

Combobox get() not returning selected value

Newbie
 
Join Date: Jul 2009
Posts: 2
#1: Jul 7 '09
I'm trying to pass a name from a ComboBox to a MySQL search function, but no matter how I twist it, the get() always returns the first value in the combobox list, regardless of which name the user selects. Any ideas why?

ComboBox Window
Expand|Select|Wrap|Line Numbers
  1. import search
  2.  
  3. def match():
  4.     #Initialize
  5.     new2 = tk.Toplevel()
  6.     new2.title("Matching Students and Projects")
  7.     title = tk.Label(new2, text = "See Student/Project matches for:", font=("Arial", 12, "bold"))
  8.     title.grid(row=0, column=0, sticky=W)
  9.  
  10.     #Create drop-down list of students
  11.     students = ['student name', 'Student Name', 'Students Named']
  12.  
  13.     Pmw.initialise()
  14.     studentmenu = Pmw.ComboBox(new2, label_text='Choose a Student:', labelpos = 'nw', scrolledlist_items=students, selectioncommand=None, entryfield_value=students[0])
  15.     studentmenu.grid(row=1, column=0, sticky=W, padx=0, pady=5)
  16.  
  17.     #run the search
  18.     close = tk.Button(new2,text="Match",command=search.search(studentmenu))
  19.     close.grid(row=2, column=0)
  20.  
  21.     #Exit
  22.     close = tk.Button(new2,text="Close Form",command=new2.destroy)
  23.     close.grid(row=2, column=0, sticky=W)
  24.     new2.mainloop()
Beginning of Search function
Expand|Select|Wrap|Line Numbers
  1. def search(menu):
  2.     #Select the student
  3.     searchname = menu.get()
  4.     searchname = searchname.split()
  5.     print searchname
  6.     fname = searchname[0]
  7.     lname = searchname[1]

Newbie
 
Join Date: Sep 2007
Location: Buffalo, NY
Posts: 25
#2: Jul 10 '09

re: Combobox get() not returning selected value


I would think it should be...

Quote:
searchname = menu.getSelected()
Just a thought.
Reply

Tags
combobox, function, get(), pmw, python