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
Beginning of Search function
ComboBox Window
Code:
import search def match(): #Initialize new2 = tk.Toplevel() new2.title("Matching Students and Projects") title = tk.Label(new2, text = "See Student/Project matches for:", font=("Arial", 12, "bold")) title.grid(row=0, column=0, sticky=W) #Create drop-down list of students students = ['student name', 'Student Name', 'Students Named'] Pmw.initialise() studentmenu = Pmw.ComboBox(new2, label_text='Choose a Student:', labelpos = 'nw', scrolledlist_items=students, selectioncommand=None, entryfield_value=students[0]) studentmenu.grid(row=1, column=0, sticky=W, padx=0, pady=5) #run the search close = tk.Button(new2,text="Match",command=search.search(studentmenu)) close.grid(row=2, column=0) #Exit close = tk.Button(new2,text="Close Form",command=new2.destroy) close.grid(row=2, column=0, sticky=W) new2.mainloop()
Code:
def search(menu): #Select the student searchname = menu.get() searchname = searchname.split() print searchname fname = searchname[0] lname = searchname[1]
Comment