|
发表于 2020-11-23 19:34:08
|
显示全部楼层
- import webbrowser
- from tkinter import *
- root = Tk()
- text = Text(root, width=30, height=5)
- text.pack()
- text.insert(INSERT, "I love FishC.com!")
- text.tag_add("link", "1.7", "1.16")
- 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):
- webbrowser.open("http://www.fishc.com")
- text.tag_bind("link", "<Enter>", show_hand_cursor)
- text.tag_bind("link", "<Leave>", show_arrow_cursor)
- text.tag_bind("link", "<Button-1>", click)
- mainloop()
复制代码
我直接复制代码,可以正常运行,光标会变化,也能打开网页。不过我发现缩进还有点细微的问题,你再试试这个吧!又改了两个缩进。 |
|