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(...)
Add load_init_file(...) or set_init_file(...) at the beginning of your app.
a. load_init_file(...) if you don't want the layout to be overwritten by the user.
b. set_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.enable_docking(dock_space=True)
# 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()
withdpg.window(label="Left", id=left_window):
passwithdpg.window(label="Right", id=right_window):
passwithdpg.window(label="Top", id=top_window):
passwithdpg.window(label="Bottom", id=bottom_window):
passwithdpg.window(label="Center", id=center_window):
passwithdpg.window(label="Temporary Window"):
dpg.add_button(label="Save Ini File", callback=lambda: dpg.save_init_file("custom_layout.ini"))
dpg.start_dearpygui()
We lay the windows out like so before saving:
Next, we modify the script like so:
importdearpygui.dearpyguiasdpgdpg.enable_docking(dock_space=True)
dpg.load_init_file("custom_layout.ini")
# 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()
withdpg.window(label="Left", id=left_window):
passwithdpg.window(label="Right", id=right_window):
passwithdpg.window(label="Top", id=top_window):
passwithdpg.window(label="Bottom", id=bottom_window):
passwithdpg.window(label="Center", id=center_window):
passdpg.start_dearpygui()
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 set_init_file(...). If you would like this same functionality without the user overwriting the default layout:
importdearpygui.dearpyguiasdpgimportosimportshutildpg.enable_docking(dock_space=True)
dpg.set_init_file(file="user_custom_layout.ini")
ifnotos.path.exists("user_custom_layout.ini"):
shutil.copy("custom_layout.ini", "user_custom_layout.ini")
# 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()
withdpg.window(label="Left", id=left_window):
passwithdpg.window(label="Right", id=right_window):
passwithdpg.window(label="Top", id=top_window):
passwithdpg.window(label="Bottom", id=bottom_window):
passwithdpg.window(label="Center", id=center_window):
passdpg.start_dearpygui()
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(...)
orset_init_file(...)
at the beginning of your app.a.
load_init_file(...)
if you don't want the layout to be overwritten by the user.b.
set_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:
![image](https://user-images.githubusercontent.com/39973752/126207707-6fee5753-dfa6-4a1d-9d9b-5671454327be.png)
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(...)
withset_init_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