0

私はこれでかなり遊んでいましたが、私はそれを台無しにしているように感じます. 誰かがテキスト フィールドに単語を入力すると、その単語を含む .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()

おそらくおわかりのように、私はこれにかなり慣れていないので、どんな助けも本当に感謝しています。

4

1 に答える 1

0

あなたのコールバックは結果を挿入していますSearch(id)が、その関数は何も返していません。テキスト ウィジェットに表示する文字列を返すには、その関数に return ステートメントを追加する必要があります。

より良い方法は、テキスト ウィジェットへの参照を渡して、Search一致するものを見つけたときに直接挿入できるようにすることです。

于 2013-05-22T12:54:01.857 に答える