2014-03-03 46 views
0

您好我有一个Python的搜索效果很好,然后我有一个接受用户输入Tkinter的GUI。用户输入然后用于使用python查询数据库。它匹配的记录一起因输入例如,当我需要它能够匹配蓝对蓝等是否有人知道如何做到这一点会匹配蓝对蓝,这里是什么,我已经有一个例子(NB它是一个编制的场景);如何使用户输入的情况下蟒搜索不区分大小写

def Search(): 
global E1, E2, E3, E4, file 


    #Open the file in read mode 
    file = sqlite3.connect('H:\\matching.db') 

    #Welcome message 
    print ("Please type in the information required") 


    window = Tk() 
    window.title ("Search for matches") 

    def QuitSearch(): 
     window.destroy() 


    #Create text that will be shown to the user 
    window.configure(bg="red") 
    Label(window, text="Please enter the colour of your hair").grid(row=0) 
    Label(window, text="Please enter the colour of your eyes").grid(row=1) 
    Label(window, text="Please enter your gender").grid(row=2) 
    Label(window, text="Please enter your shoe size").grid(row=3) 


    #Create where the user will input 
    E1= Entry(window) 
    E2= Entry(window) 
    E3= Entry(window) 
    E4= Entry(window) 

    #Assigning the input boxes to area on the screen 
    E1.grid(row=0, column=1) 
    E2.grid(row=1, column=1) 
    E3.grid(row=2, column=1) 
    E4.grid(row=3, column=1) 

    button = Button(window, text = "Submit information", command=Submit, fg="yellow", bg="black") 
    button.grid(row=3, column=2, padx = 5) 


    quitbutton = Button (window, text ="QUIT", command=QuitSearch, fg ="red") 
    quitbutton.grid(row=3, column=3, padx=5) 







#The submit function allows the data inserted by the user in Search to be submitted and to search the database  
def Submit(): 
    global E1, E2, E3, E4, file 

    #Retaining user input 
    eyecolour = E1.get() 
    haircolour = E2.get() 
    gender = E3.get() 
    shoesize = E4.get() 



    #The search 
    cursor = file.execute ('''SELECT ID, forename, surname, FROM people 
    WHERE eyecolour =? and haircolour=? and gender=? and shoesize=? ''', (eyecolour, haircolour, gender, shoezize)) 

    window=Tk() 
    def QuitOutputScreen(): 
    window.destroy() 

    for row_number, row in enumerate(cursor): 
     Label(window, text ="ID = "+ str(row[0])).grid(row=1, column = row_number) 
     Label(window, text ="Forename = "+str(row[1])).grid(row=2, column = row_number) 
     Label(window, text ="Surname = "+(row[2])).grid(row=3, column = row_number) 


    Label(window, text ="Search complete ").grid(column=11) 

    quitbutton = Button (window, text ="QUIT", command=QuitOutputScreen, fg ="red") 
    quitbutton.grid(row=11, column=11, padx=5) 


file.close() 
+0

全局变量是一个坏主意。 –

回答

0

在你的Python代码,你可以存储和搜索使用所有大写或小写,通过使用字符串下限和上限函数或者你可以使用正则表达式和re.IGNORE_CASE做你的搜索。

对于DB查询您可以存储所有固定的情况下,或者告诉DB引擎忽略大小写。