How can i unlock Gtk button event

When i click on some button, the entire application stay locked waiting a result from the method, to return something..

So, i have one Gtk.Button, and i connected him to a function, for example on_button_clicked:

button = Gtk.Button()
button.connect('clicked', on_button_clicked)

the function on_button_clicked look like this:

def on_button_clicked(widget):

When the functions (func1, func2, func3) is runing, the entire application stops, waiting a result from the main function (on_button_clicked). The os say 'The Application is not responding'.

Basicaly, the func1 encode one url, request that url using urllib, that request return a response that is a json file, then the func2 load that json, then make a dict with informations from json, and make an iteration in this dict printing the informations.

        url = ''

        values = OrderedDict([
            ('api_key', '47a28953049fe88b32522c8997e712bb'),
            ('text', term.replace(' ', '+')),
            ('format', 'json'),

        url_encoded = urllib.urlencode(values)
        url_encoded = urllib.unquote(url_encoded)

        request = Request(url_encoded[4:])
            response = urlopen(request, timeout =1)
        except urllib2.URLError, e:
            print 'There was an error: %r' %e

In this time i can't click or edit no other widget.


func1(), func2() and func3() are blocking the gtk main loop. In this case, it is probably the network request. Therefore, you have to use threads.

Probably something like this:

from threading import Thread
def on_button_clicked(widget):

However, you should note that you have to use glib.idle_add(), if you want to modify gtk widgets from a thread. To hide a widget from a Thread for example, you would do glib.idle_add(widget.set_visible, False).

Need Your Help

Andengine Configuration Error For Eclipse

eclipse configuration andengine

I'm trying to configure andengine on eclipse. there are some warnings in andengine default folder in src folder. I didn't change anything. I build it with api 15.

Can't get mouse callback to work with java swing

java swing matlab

I would like to get eventData when the mouse is clicked or dragged along a slider. I have tried suggestions across blog posts ( and the