MightyInSpirit
MightyInSpirit

Reputation: 185

Tkinter Progressbar Movement Speed Change?

It is possible to change the movement speed of Tkinter progressbar when configured in indeterminate state?

Upvotes: 0

Views: 2054

Answers (2)

MightyInSpirit
MightyInSpirit

Reputation: 185

I found an elegant way, in case anyone is still looking.

The .start() method on a ttk.Progressbar can accept an argument to specify the interval in milliseconds.

.start([interval])

Start moving the indicator every interval milliseconds; the default is 50ms. Each time, the indicator is moved as if you called the .step() method.

Here's the sample code to try it yourself:

import tkinter as tk
from tkinter import ttk

root = tk.Tk()

p10 = ttk.Progressbar(root, mode='indeterminate', length=200)
p10.pack()
p10.start(10)

p100 = ttk.Progressbar(root, mode='indeterminate', length=200)
p100.pack()
p100.start(100)

p1000 = ttk.Progressbar(root, mode='indeterminate', length=200)
p1000.pack()
p1000.start(1000)

root.mainloop()

Upvotes: 1

furas
furas

Reputation: 142804

You can use after(milliseconds, function_name) to run periodically own function which will use step() to change value in progressbar. If you use different milliseconds or different value in step() then it will move with different speed.

import tkinter as tk
from tkinter import ttk

def change():
    p.step(10)
    root.after(100, change) # run again after 100ms,

root = tk.Tk()

p = ttk.Progressbar(root, mode='indeterminate')
p.pack()

change() # run first time 

root.mainloop()

Upvotes: 2

Related Questions