1

I am using the DearPyGui library for creating a user interface in python.

In a function that runs my algorithm, the algorithm needs some input from the user (yes/no question). Is it possible to easily implement such a messagebox in DearPyGui without braking the flow of the function?

Something like this:

def runAlgorithm():
    a = 2 + 2
    user_choice = dpg.messageBox("Do you want to add or subtract the values", ["add", "subtract"]
    if user_choice == "add":
        a = a + a
    else:
        a = a - a
    print("The user has selected %s and the result is %d"%(user_choice, a)

As I understand DearPyGui until now, this is not possible and I have to write something like this, which is quite bulky and unreadable and especially in algorithms that might need some user input greatly disrupts their readability.

def choiceAdd(sender, app_data, user_data):
    a = user_data[0]
    print("The user has selected %s and the result is %d"%("add", a + a)
def choiceSub(sender, app_data, user_data):
    a = user_data[0]
    print("The user has selected %s and the result is %d"%("subtract", a - a)

def runAlgorithm():
    a = 2 + 2
    with dpg.window():
        dpg.add_button("add", callback = choiceAdd, user_data = [a])
        dpg.add_button("subtract", callback = choiceSub, user_data = [a]
    user_choice = dpg.messageBox("Do you want to add or subtract the values", ["add", "subtract"]
    if user_choice == "add":
        a = a + a
    else:
        a = a - a
    print("The user has selected %s and the result is %d"%(user_choice, a)

Any help is recommended. Thank you in advance

christoph
  • 11
  • 1

0 Answers0