Progress Bar - Tkinter

Asked

Viewed 1,902 times

0

While processing takes place, the screen has to display a progress bar pro user. What is the logic behind this (Python, Tkinter)? How to make the progress bar appear on the screen while processing is going on?

  • You have many ways of doing this: concorrência, paralelismo or even a loop.

1 answer

1


To update the progress bar, associate a Tkinter variable in it:

import tkinter as t
from tkinter import ttk

root = t.Tk()

.... # codigo definindo o resto da interface ...

var_barra = t.DoubleVar()
minha_barra = ttk.Progressbar(root, variable=var_barra, maximum=30)

Then just update this variable once in a while, and call the root.update() to update on the screen!

var_barra.set(k) # k é um número entre 0 e o máximo 
                 # (definido como 30 no exemplo acima)
root.update()

The time and correct way to call these functions depends on the processing you are doing! In general you can use the root.after() to call a function multiple times automatically.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.