【发布时间】:2015-03-01 20:54:29
【问题描述】:
我正在 Tkinter 中编写一个 GUI,它所要做的就是有一个搜索框,然后将结果作为超链接输出。我有很多麻烦。最好的方法是什么?
一旦找到搜索词,我就可以打开很多网页。但我希望能够显示超链接并让用户选择打开哪个。任何帮助表示赞赏。谢谢!
这是我目前的代码:
from Tkinter import *
import json
import webbrowser
with open('data.json', 'r') as f:
database = json.loads(f.read())
def goto(event,href):
webbrowser.open_new(href)
def evaluate(event):
res.delete(1.0, END)
search_param = str(entry.get())
for patient_id in database:
if search_param in str(database[patient_id]).lower():
href = "https://website.com/" + str(patient_id)
res.insert(INSERT, href, "link")
res.bind("<Button-1>", goto(event, href))
w = Tk()
Label(w, text="Search:").pack()
entry = Entry(w)
entry.bind("<Return>", evaluate)
entry.pack()
res = Text(w)
res.pack()
w.mainloop()
【问题讨论】:
标签: python text hyperlink tkinter widget