tags:

views:

56

answers:

1

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 this event.

sorry for my english :)

+1  A: 

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()
ptomato