part of GtkLabel clickable
How to do, that just a part of GtkLabel has a clicked event and calls a function.
I make a twitter client, witch shows tweets and i would like to, when in the tweet is a # hashtag and I click it, the application shows a new window with search of this #hashtag. and I dont know how to do that just the #hashtag would invoke thi开发者_运维技巧s event.
You can surround the clickable part in <a>
tags and connect to the activate-link
signal.
Here is an example:
import gtk
def hashtag_handler(label, uri):
print('You clicked on the tag #%s' % uri)
return True # to indicate that we handled the link request
window = gtk.Window()
label = gtk.Label()
label.set_markup('Unclickable line\nLine with a <a href="hashtag">#hashtag</a>\nLine with a <a href="different">#different</a> hashtag')
label.connect('activate-link', hashtag_handler)
window.add(label)
window.connect('destroy', gtk.main_quit)
window.show_all()
gtk.main()
精彩评论