SeaDog
SeaDog

Reputation: 121

Displaying a change immediately on a GTK GUI

So I have this Gtk.Button object that basically calls a custom bash command and displays an a very large dataset in a new window. After being pressed, it can take anywhere between 3-10 seconds to display the new window. What I want to do is change the label of the button to something like "Loading...' between the time of when the button is pressed and when the window finally pops up. However, with my current code it the label doesn't change until the window has popped up. This is essentially what I have:

    self.button.set_label("Loading...")
    self.show_all()
    win = NewWindow()
    win.connect("destroy", Gtk.main_quit)
    win.show_all()
    Gtk.main()

Upvotes: 0

Views: 380

Answers (1)

SeaDog
SeaDog

Reputation: 121

This is what I did:

self.button.set_label("Loading...")
while Gtk.events_pending():
    Gtk.main_iteration()
win = NewWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()

When clicked, the button displays "Loading" and does so until the new window is opened. The loop lets you update the UI during a long computation.

Upvotes: 1

Related Questions