Connecting Tech Pros Worldwide Help | Site Map

Combobox get() not returning selected value

  #1  
Old July 7th, 2009, 10:24 PM
Newbie
 
Join Date: Jul 2009
Posts: 2
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]

Last edited by bvdet; July 8th, 2009 at 02:30 PM. Reason: changed quote tags to code tags
  #2  
Old July 10th, 2009, 06:35 PM
Newbie
 
Join Date: Sep 2007
Location: Buffalo, NY
Posts: 25

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
ComboBox - Setting the SelectedIndex - Throwing an error john.halet@usa.net answers 5 November 21st, 2005 08:42 PM
Error Trapping In Access 2000 Peter Frost answers 6 November 12th, 2005 11:14 PM
Error Trapping In Access 2000 Peter Frost answers 6 November 12th, 2005 10:50 PM