Dearpygui - built another window within an callback

1.6k Views Asked by At

Hello my fellow programmer! In my endless searcch for an suiteble GUI i found these wonderfull modul calles dearpygui. After i started to learn more about how to built a GUI with these, i came to the point where i just asked me: "How can i built a window inside of an callback, is this even possible?" Maybe you awesome people, can help me with my little question!

Thanks in advance Freddie

This is my code solong... Maybe anyone get it and can help me out!

import dearpygui.dearpygui as dpg

item_table = []

#builts the context window
dpg.create_context()
dpg.create_viewport(title="invengo", width=600, height=600)

#outputs the data from the inputs and callbacks
def reg(sender):
    print(dpg.get_value(sender))
    item_table.append(dpg.get_value(sender))

def lel(sender):
    with dpg.window(tag="PW"):
        

#builts the datainputs 
with dpg.window(tag="PW"):
    item_name = dpg.add_input_text(label="Gegenstand", hint="Hier den Namen des Gegenstandes eintragen...",callback=reg, on_enter=True)
    item_amount = dpg.add_combo(label="Menge", default_value=1, items=(1,2,3,"Mehrere"), callback=reg)
    check_button = dpg.add_button(label="CLICK ME", callback=lel)
dpg.set_item_callback(item_name, reg)

#debugging
print(dpg.get_value(item_name))

#start the modul  
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.set_primary_window("PW", True)
dpg.start_dearpygui()
dpg.destroy_context()

#debugging
print(item_table)
1

There are 1 best solutions below

0
On

I was able to run your code just by changing the callback function lel to:

def lel(sender):
    with dpg.window():
        pass

and could generate many child windows. You see that I removed the tag. Tags must be unique, but you used the same one as in your main window, which is not allowed. Also note the need of the pass dummy statement at the end of an empty with block.