i was trying to use tabs in dearpygui and it gives me this error:
Traceback (most recent call last):
File "c:\main.py", line x, in <module>
with dpg.add_tab_bar():
AttributeError: __enter__
i tried to do it like this
dpg.add_tab_bar('tabbar')
dpg.add_tab('tab1')
dpg.add_checkbox(label='checkbox')
dpg.end_tab()
dpg.end_tab_bar()
id didnt work to
the code:
import dearpygui.dearpygui as dpg
with dpg.window(label="window") as mainwind:
with dpg.add_tab_bar():
with dpg.add_tab(label='tab1'):
dpg.add_checkbox(label='checkbox')
dpg.start_dearpygui()
I digg in source code of demo and you simply mix different methods.
If you use with
then use function WITHOUT add_
import dearpygui.dearpygui as dpg
with dpg.window(label="window"): # without `add_`
with dpg.tab_bar(label='tabbar'): # without `add_`
with dpg.tab(label='tab1'): # without `add_`
dpg.add_checkbox(label='Hello')
with dpg.tab(label='tab2'): # without `add_`
dpg.add_checkbox(label='World')
dpg.start_dearpygui()
And the same without with
but it needs add_
and parent=
import dearpygui.dearpygui as dpg
window = dpg.add_window(label="window")
tabbar = dpg.add_tab_bar(label='tabbar', parent=window)
tab1 = dpg.add_tab(label='tab1', parent=tabbar)
dpg.add_checkbox(label='Hello', parent=tab1)
tab2 = dpg.add_tab(label='tab2', parent=tabbar)
dpg.add_checkbox(label='World', parent=tab2)
dpg.start_dearpygui()
And mix of both methods
import dearpygui.dearpygui as dpg
with dpg.window(label="window"): # without `add_`
tabbar = dpg.add_tab_bar(label='tabbar') # without `parent`
tab1 = dpg.add_tab(label='tab1', parent=tabbar)
dpg.add_checkbox(label='Hello', parent=tab1)
tab2 = dpg.add_tab(label='tab2', parent=tabbar)
dpg.add_checkbox(label='World', parent=tab2)
dpg.start_dearpygui()
If you use with ... as name:
then you can use name
as parent
but you may also skip it.
import dearpygui.dearpygui as dpg
with dpg.window(label="window") as window: # without `add_`
#tabbar = dpg.add_tab_bar(label='tabbar') # without `parent`
tabbar = dpg.add_tab_bar(label='tabbar', parent=window) # or with `parent`
tab1 = dpg.add_tab(label='tab1', parent=tabbar)
dpg.add_checkbox(label='Hello', parent=tab1)
tab2 = dpg.add_tab(label='tab2', parent=tabbar)
dpg.add_checkbox(label='World', parent=tab2)
dpg.start_dearpygui()
BTW: and text you have to always use with label=