所有代码及解释如下:from tkinter import *
import webbrowser # 用于在点击一个标记文本(一个链接)时实现打开网页的效果
root=Tk()
savephoto=[] # 用于存储PhoteImage组件,必须,否则组件会丢失无法正常显示
def hello(event):print('Got tag event !')
def show_hand2_cursor(event): # 定义函数,显示手形(指针指向Quit按钮,标记文本以及图片时会用到),会绑定到鼠标指向时的事件
text.config(cursor='hand2')
def show_xterm_cursor(event): # 定义函数,显示光标(指针指向空白时会用到),会绑定到鼠标移除事件
text.config(cursor='xterm')
def show_arrow_cursor(event): # 定义函数,显示箭头,会绑定到鼠标指向链接时的事件
text.config(cursor='arrow')
def click(event): # 定义函数,打开一个链接,会绑定到鼠标单击链接的事件中
webbrowser.open('http://www.baidu.com')
def showpic(event): # 定义函数,
win=Toplevel(width=180,height=120)
win.title('PythonPowered')
imgobj=PhotoImage(file=r'D:\Program Files (x86)\project\Programming \images\PythonPowered.gif')
Label(win,image=imgobj).pack(expand=YES,fill=BOTH)
savephoto.append(imgobj)
text=Text(root)
root.title('TextTags')
text.config(font=('courier',15,'normal'))
text.config(width=25,height=13)
text.pack(expand=YES,fill=BOTH)
text.insert(END,'This is\n\nthe meaning\n\nof life.\n\nhttp://www.baidu.com\n\n')
btn=Button(text,text='Quit',cursor='hand2',command=root.quit) # 定义一个按钮组件,用于退出程序