You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Saving a window docking layout is a 4 step process:
Run the app as is.
Layout the windows how you want.
Save the layout with save_init_file(...)
Configure app with load_init_file or init_file :
a. load_init_file if you don't want the layout to be overwritten by the user.
b. init_file if you want the user's run time changes to be saved.
Example
For the first run, we use the following:
importdearpygui.dearpyguiasdpgdpg.create_context()
dpg.configure_app(docking=True, docking_space=True) # must be called before create_viewportdpg.create_viewport()
dpg.setup_dearpygui()
# generate IDs - the IDs are used by the init file, they must be the# same between sessionsleft_window=dpg.generate_uuid()
right_window=dpg.generate_uuid()
top_window=dpg.generate_uuid()
bottom_window=dpg.generate_uuid()
center_window=dpg.generate_uuid()
dpg.add_window(label="Left", tag=left_window)
dpg.add_window(label="Right", tag=right_window)
dpg.add_window(label="Top", tag=top_window)
dpg.add_window(label="Bottom", tag=bottom_window)
dpg.add_window(label="Center", tag=center_window)
withdpg.window(label="Temporary Window"):
dpg.add_button(label="Save Ini File", callback=lambda: dpg.save_init_file("custom_layout.ini"))
# main loopdpg.show_viewport()
whiledpg.is_dearpygui_running():
dpg.render_dearpygui_frame()
dpg.destroy_context()
We lay the windows out like so before saving:
Next, we modify the script like so:
importdearpygui.dearpyguiasdpgdpg.create_context()
dpg.configure_app(docking=True, docking_space=True, load_init_file="custom_layout.ini") # must be called before create_viewportdpg.create_viewport()
dpg.setup_dearpygui()
# generate IDs - the IDs are used by the init file, they must be the# same between sessionsleft_window=dpg.generate_uuid()
right_window=dpg.generate_uuid()
top_window=dpg.generate_uuid()
bottom_window=dpg.generate_uuid()
center_window=dpg.generate_uuid()
dpg.add_window(label="Left", tag=left_window)
dpg.add_window(label="Right", tag=right_window)
dpg.add_window(label="Top", tag=top_window)
dpg.add_window(label="Bottom", tag=bottom_window)
dpg.add_window(label="Center", tag=center_window)
# main loopdpg.show_viewport()
whiledpg.is_dearpygui_running():
dpg.render_dearpygui_frame()
dpg.destroy_context()
With the above script, the app will always open with the saved layout. If you would like the user's changes to be saved between sessions, replace load_init_file with init_file. If you would like this same functionality without the user overwriting the default layout:
importdearpygui.dearpyguiasdpgimportosimportshutilifnotos.path.exists("user_custom_layout.ini"):
shutil.copy("custom_layout.ini", "user_custom_layout.ini")
dpg.create_context()
dpg.configure_app(init_file="user_custom_layout.ini", docking=True, docking_space=True) # must be called before create_viewportdpg.create_viewport()
dpg.setup_dearpygui()
# generate IDs - the IDs are used by the init file, they must be the# same between sessionsleft_window=dpg.generate_uuid()
right_window=dpg.generate_uuid()
top_window=dpg.generate_uuid()
bottom_window=dpg.generate_uuid()
center_window=dpg.generate_uuid()
dpg.add_window(label="Left", tag=left_window)
dpg.add_window(label="Right", tag=right_window)
dpg.add_window(label="Top", tag=top_window)
dpg.add_window(label="Bottom", tag=bottom_window)
dpg.add_window(label="Center", tag=center_window)
# main loopdpg.show_viewport()
whiledpg.is_dearpygui_running():
dpg.render_dearpygui_frame()
dpg.destroy_context()
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Answer
Saving a window docking layout is a 4 step process:
save_init_file(...)
load_init_file
orinit_file
:a.
load_init_file
if you don't want the layout to be overwritten by the user.b.
init_file
if you want the user's run time changes to be saved.Example
For the first run, we use the following:
We lay the windows out like so before saving:
Next, we modify the script like so:
With the above script, the app will always open with the saved layout. If you would like the user's changes to be saved between sessions, replace
load_init_file
withinit_file
. If you would like this same functionality without the user overwriting the default layout:Resources
Notes
Beta Was this translation helpful? Give feedback.
All reactions