LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-12-2018, 03:26 PM   #1
j4g
LQ Newbie
 
Registered: Aug 2018
Posts: 3

Rep: Reputation: Disabled
GTK in C - How to update a label from within a function


I'm struggling with something that seems trivially simple (please don't laugh).

I have a button whose callback function looks like this:

Code:
void function() {
    gtk_label_set_text(label, "Hello");

    /*
     *
     * Other stuff
     *
     */
}
I expect this function change the label's text to "Hello" and then perform "other stuff", in that order. However, the label doesn't update until the whole function finishes.

How can I update the label (or perhaps "refresh" the window that the label is a part of) before "other stuff" happens?
 
Old 08-12-2018, 06:56 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
https://developer.gnome.org/gtk3/sta...tk-widget-show
 
1 members found this post helpful.
Old 08-13-2018, 07:35 AM   #3
j4g
LQ Newbie
 
Registered: Aug 2018
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thank you for your reply. Unfortunately, calling gtk_widget_show() doesn't seem to make a difference, at least not in my case.

I'm thinking that although functions like gtk_label_set_text() and gtk_widget_show() modify some internal values of the widgets, the actual redrawing (from the user's perspective) doesn't happen until the callback function terminates.

I thought I could get around this by assigning two callback functions to the same widget, one for handling the label and one for handling the other stuff, but unfortunately it had the same result (the widget didn't get redrawn until both functions terminated).

Just to be clear, my desired sequence is:

1. User interacts with widget (clicks a button in this case)
2. Label changes
3. Other stuff happens

It seems that no matter what I do, 2 and 3 always happen out of order from the user's perspective...
 
Old 08-13-2018, 07:59 AM   #4
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
try
Code:
while(gtk_events_pending())
	gtk_main_iteration();
After setting the label.
 
Old 08-15-2018, 08:35 AM   #5
j4g
LQ Newbie
 
Registered: Aug 2018
Posts: 3

Original Poster
Rep: Reputation: Disabled
Yes, that did the trick.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
GTK+: Change the font of GtkButton label Hamed Programming 3 11-16-2010 04:58 PM
[GTK] positioning gtk label in viewport container Kadabra Programming 0 10-29-2009 09:45 AM
Mono : GTK# and changing a label's font size drydo Programming 0 10-16-2009 11:13 AM
Gtk->label() _ AsiF Linux - Software 1 05-12-2008 06:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration