PyGTK ProgressBar Class - PyGTK

What is PyGTK ProgressBar Class?

Progress bars are used to offer user the visual sign of a long running process. The gtk.ProgressBar widget can be used in two modes — percentage mode and activity mode.

When it is likely to precisely guess how much of work is undecided to be finished, the progress bar can be used in percentage mode, and the user sees an incremental bar display percentage of completed job. If on the other hand, the amount of work to be completed can be precisely determined, the progress bar is used in activity mode in which, the bar shows the activity by displaying a block moving back and forth.

The resulting constructor initializes the widget of the gtk.ProgressBar class –

gtk.ProgressBar uses the resulting methods to manage functionality −

  • ProgressBar.pulse() − This nudges the progressbar to specify that some progress has been made, but you don't know how much. This method also changes the progress bar mode to "activity mode," where a block bounces back and forth.
  • ProgressBar.set_fraction(fraction) − This causes the progress bar to "fill in" the portion of the bar specified by fraction. The value of fraction should be between 0.0 and 1.0.
  • ProgressBar.set_pulse_setup() − This sets the portion (specified by fraction) of the total progress bar length to move the bouncing block for each call to the pulse() method.
  • ProgressBar.set_orientation() − This sets the orientation of the progress bar. It may be set to one of the resulting constants:

In the resulting program, the gtk.ProgressBar widget is used in activity mode. Therefore, the initial position of progress is set to 0.0 by the set_fraction()method.

In order to increment the progress by 1 percent after 100 milliseconds, a timer object is declared and a callback function is set up to be invoked after every 100 ms so that the progress bar is updated.

Now, progress_timeout() is the callback function. It increments the parameter of the set_fraction() method by 1 percent and updates the text in progress bar to show the percentage of completion.


Observe the resulting code –

The above code will generate the resulting output –

To use the progress bar in activity mode, change callback function to the resulting and run –

The back and forth movement of a block inside the Progress bar will show the progress of the activity.


All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

PyGTK Topics