繁体   English   中英

Dearpygui - 在回调中构建了另一个 window

[英]Dearpygui - built another window within an callback

你好,我的程序员伙伴。 在我对合适的 GUI 的无休止搜索中,我发现了这些很棒的模块调用 dearpygui,在我开始学习更多关于如何使用这些构建 GUI 之后:我来到了我刚才问我的地步,“我如何在里面构建一个 window回调?这甚至可能吗,“也许你们这些了不起的人,可以帮我解决我的小问题!

在此先感谢房地美

这是我的代码……也许任何人都可以帮助我!

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)

只需将回调lel lel 更改为:

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

并且可以生成许多子 windows。你看我删除了tag 标签必须是唯一的,但你使用了与主 window 中相同的标签,这是不允许的。 还要注意在空with块的末尾需要pass伪语句。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM