|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
当前代码
one = getlist() #热榜list
two = getline() #热榜对应链接
root = Tk()
root.title('百度贴吧热榜')
sb = Scrollbar(root)
sb.pack(side=RIGHT,fill=Y)
text = Text(root,width=30,height=30,yscrollcommand=sb.set)
text.pack(side=LEFT)
sb.config(command=text.yview)
def show_arrow_cursor(event):
text.config(cursor = "arrow")
def show_xterm__cursor(event):
text.config(cursor = "xterm")
def click(event):
webbrowser.open(tow)
for i,each in enumerate(one):
text.insert(END,each)
text.tag_add("link","0.0",'1.10')
text.insert(END,'\n')
text.insert(END,'\n')
text.tag_config("link",foreground = 'blue',underline = True)
text.tag_bind("link",'<Enter>',show_arrow_cursor)
text.tag_bind("link",'<Leave>',show_xterm__cursor)
text.tag_bind("link",'<Enter>',click)
mainloop()
-------------------------------------------------------
已经获得热榜词条列表和超链接列表
现在需要打印出热榜列表,当点击热榜词条触发超链接
问题:
1、我要怎么绑定每个词条,对应超链接
2、每个词条都要添加下横线
请问下大神我要如何修改?
本帖最后由 isdkz 于 2022-5-12 11:25 编辑
参考代码:from tkinter import *
import webbrowser
from functools import partial
one = ['测试一', '测试二', '测试三','测试四', '测试五'] #热榜list
two = [
'http://www.baidu.com',
'http://www.qq.com',
'http://www.zhihu.com',
'http://www.taobao.com',
'http://www.bing.com
] #热榜对应链接
root = Tk()
root.title('百度贴吧热榜')
sb = Scrollbar(root)
sb.pack(side=RIGHT,fill=Y)
text = Text(root,width=30,height=30,yscrollcommand=sb.set)
text.pack(side=LEFT)
sb.config(command=text.yview)
def show_arrow_cursor(event):
text.config(cursor = "arrow")
def show_xterm__cursor(event):
text.config(cursor = "xterm")
def click(event, u):
webbrowser.open(u)
for i,each in enumerate(one):
text.insert(END,each,i)
text.insert(END,'\n')
text.insert(END,'\n')
for i, j in zip(range(len(one)), two):
text.tag_config(i,foreground = 'blue',underline = True)
text.tag_bind(i,'<Enter>',show_arrow_cursor)
text.tag_bind(i,'<Leave>',show_xterm__cursor)
text.tag_bind(i,'<Button-1>',partial(click, u=j))
mainloop()
|
|