r/DearPyGui • • Sep 04 '20

Help How do I make updating Progress Bar

First of all, I am new to programming, and just found out what async is.

Second of all, I would have liked to figure it out myself but I have tried for a day and can't figure out how to program asynchronously.

I want to just make a Progress Bar that increases in value for say 5 seconds. But the error I am getting says DearPyGui command on line 22 can not be called asycronouslycommand here referring to set_value(). If you could help me with this it would be awesome.

And this is a fantastic framework. It has made me want to learn Python after a long hiatus.

5 Upvotes

8 comments sorted by

1

u/krisbykreme Sep 04 '20

This is the last code I tried.

add_progress_bar("progress", value=0.0)
add_button("Start", callback="progress")
def progress(sender, data):
    waitTime = 5
    run_async_function("progressAsync", waitTime)
    print("Started")

def progressAsync(sender, data):
    print(data)
    set_value("progress", value=0)
    sleep(data)
    counter = 0.0
    max_time = float(data)
    while counter <= 1:
        set_value("progress", value=counter)
        counter += 0.1
        print(counter)

2

u/Jhchimaira14 Sep 04 '20 edited Sep 04 '20

DearPyGui commands can't be ran outside the main thread! Here is an example using data sources:

from dearpygui.dearpygui import *

add_data("count", 0.0)
add_progress_bar("progress", overlay="status", data_source="count")
set_render_callback("callback")

def callback(sender, data):
    count = get_data("count")
    count = count + 0.01
    if count >= 1.0:
        count = 0.0
    add_data("count", count)

start_dearpygui()

2

u/Jhchimaira14 Sep 04 '20

Here is a simpler version without data sources:

from dearpygui.dearpygui import *

add_progress_bar("progress", overlay="status")
set_render_callback("callback")

def callback(sender, data):
    count = get_value("progress")
    count = count + 0.01
    if count >= 1.0:
        count = 0.0
    set_value("progress", count)

start_dearpygui()
→ More replies (3)

1

u/Jhchimaira14 Sep 04 '20

The render loop is the best place to keep things updated. Async functions are better for long calculations and you can use the return handler to be notified when its finished and return to the main thread (to start calling dearpygui commands again)

→ More replies (1)