0
我一直在玩這個相當多的東西,而且我覺得自己弄得一團糟。 我需要一個界面,如果有人在文本字段中輸入一個單詞,它會在包含該單詞旁邊框中的.txt文件中打印任何行。 這是我到目前爲止有:根據用戶輸入構建一個搜索.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()
我很新的這一點,因爲你可能會說 - 因此,任何幫助將是非常讚賞。
也許更適合@ http://codereview.stackexchange.com/ –
你的問題是什麼?你有什麼需要幫助的? –
@BryanOakley嘿,我真的很新鮮。我不明白爲什麼它不會在文本框中打印結果。我已經設法讓它達到它進行搜索的地步,然後它將它打印在命令提示符中。謝謝 – user2409236