0
votes

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()
1
Your code is too small for me to help. For what I understand, the task that uses a lot of time is win = NewWindow(). Since you do not call Gtk.main() before showing the window, the self window is not refreshed. Remember that GUI need an event loop to process the GUI update requests. You might have to do the code in NewWindow in a separated thread (calling the batch and get its result) then update your GUIuser1531591
A solution could be to force the refresh of the GUI by calling while Gtk.events_pending(): Gtk.main_iteration() after GtkButton.set_labeluser1531591
This worked, thanks!SeaDog

1 Answers

1
votes

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.