def callback_text(event):
txt_keyword = event.widget.cget("text")
idx_start = txt_keyword.find("https")
idx_end = len(txt_keyword) - 1
url = txt_keyword[idx_start : idx_end]
webbrowser.open_new(url)
event.widget.config(text = "X |" + txt_keyword)
def changeBGLeave(event):
event.widget.config(fg="red")
def changeBGEnter(event):
event.widget.config(fg="blue")
lbl = Label(root, text = txt_content , fg="blue", cursor="hand2")
lbl.pack(anchor="w")
lbl.bind("<Button-1>", callback_text)
lbl.bind("<Enter>",changeBGLeave)
lbl.bind("<Leave>",changeBGEnter)
http://stackoverflow.com/questions/4299145/getting-the-widget-that-triggered-an-event
0 意見:
張貼留言