2012-05-11 92 views
0

我想答案是否定的,但我必須問... 我在python/tkinter中編寫了一個wiki,超鏈接由tkHyperlinkManager管理(http://effbot.org /zone/tkinter-text-hyperlink.htm)。 一切都很完美,但我也想使用可點擊的圖像 - 有可能嗎?我看到標記,超鏈接工作,我無法找到一個方法來添加標籤的圖像image in python/Tkinter中的超鏈接

亞歷山德羅

+0

我看不出有任何理由爲什麼你不應該能夠創建可點擊的圖像,因爲'Text'小部件可以包含'Tkinter.PhotoImage'情況下... – mgilson

+0

細算多一點,我認爲你可能是對的 - 一種解決方法是將圖像放入標籤中,使用'window_create'插入標籤,然後將回調與標籤綁定。 (你可能會破解一切,進入tkHyperlinkManager測試你是否收到了PhotoImage或文本)...... – mgilson

回答

1

tkHyperLinkManager不支持它,但它是非常簡單的與已內置於文字插件的功能。您需要做的只是爲您的圖像創建一個標籤,嵌入標籤併爲標籤添加綁定。

例如:

import Tkinter as tk 
... 
image_link = tk.Label(text_widget, image=my_image, cursor="left_ptr") 
image_link.bind("<1>", do_something) 
text_widget.window_create("insert", window=image_link) 
+0

非常感謝! – alessandro