我一直在玩这个很多,我觉得我把它弄得一团糟。我需要一个界面,如果有人在文本字段中输入一个单词,它会在旁边的框中打印包含该单词的 .txt 文件中的任何行。这是我到目前为止所拥有的:
    import Tkinter as tk
    from Tkinter import *
    from scipy import *
    import math
    def cbc(id, tex):
        return lambda : callback(id, tex)
    def callback(id, tex):                                 
        t = Search(id)
        tex.insert(tk.END, t)
        tex.see(tk.END)
    #def retrieve_input():
    #    input = self.entn.get("0.0",END)
    def Search(id):
        with open("file.txt", "r") as s:
            searchlines = s.readlines()
        for i, line in enumerate(searchlines):             
            if entn.get() in line: 
                for line in searchlines[i:i+1]: print line,    
                print
    top = tk.Tk()
    tex = tk.Text(master=top)                              
    tex.pack(side=tk.RIGHT)                                
    bop = tk.Frame()
    bop.pack(side=tk.LEFT)                                 
    entn = tk.Entry()
    entn.pack(side=tk.TOP, fill=Y)                         
    tb = "Search"
    b = tk.Button(bop, text=tb, command=cbc(id, tex))   
    b.pack()
    tk.Button(bop, text='Exit', command=top.destroy).pack() 
    top.mainloop()
正如您可能知道的那样,我对此很陌生 - 所以任何帮助都将不胜感激。