Combobox get() not returning selected value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SnakesRule
    New Member
    • Jul 2009
    • 2

    Combobox get() not returning selected value

    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
    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()
    Beginning of Search function
    Code:
    def search(menu):
        #Select the student
        searchname = menu.get()
        searchname = searchname.split()
        print searchname
        fname = searchname[0]
        lname = searchname[1]
    Last edited by bvdet; Jul 8 '09, 01:30 PM. Reason: changed quote tags to code tags
  • Silgd1
    New Member
    • Sep 2007
    • 25

    #2
    I would think it should be...

    searchname = menu.getSelecte d()
    Just a thought.

    Comment

    Working...