|

楼主 |
发表于 2018-4-29 21:38:20
|
显示全部楼层
本帖最后由 一鱼 于 2018-4-29 21:52 编辑
好吧,最后还是百度到了 原文是这个https://blog.csdn.net/tinym87/article/details/6957438
有需要的可以看看
代码如下:
- from tkinter import *
- import webbrowser
- url =['www.hao123.com','www.baidu.com','www.taobao.com']
- name =['hao123','百度','淘宝']
- root = Tk()
- text =Text(root,width=30,height=5,font=('微软雅黑',15))
- text.pack()
- text.tag_config('link',foreground='blue',underline=True)
- def show_hand_cursor(event):
- text.config(cursor='arrow')
- def show_arrow_cursor(event):
- text.config(cursor='xterm')
- def click(event,x):
- webbrowser.open(x)
- def handlerAdaptor(fun,**kwds):
- return lambda event,fun=fun,kwds=kwds:fun(event,**kwds)
- m=0
- for each in name:
- text.tag_config(m,foreground='blue',underline=True)
- text.tag_bind(m,'<Enter>',show_hand_cursor)
- text.tag_bind(m,'<Leave>',show_arrow_cursor)
-
- text.insert(INSERT,each+'\n',m)
- text.tag_bind(m,'<Button-1>',handlerAdaptor(click,x=url[m]))
- m+=1
- mainloop()
复制代码
|
|