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
There are several ways you could make your own message box. Most will follow a pattern similar to the example below. This example demonstrates a function that creates a centered modal popup window that is destroyed after the user makes a selection.
Example
importdearpygui.dearpyguiasdpgdefshow_info(title, message, selection_callback):
# guarantee these commands happen in the same framewithdpg.mutex():
viewport_width=dpg.get_viewport_client_width()
viewport_height=dpg.get_viewport_client_height()
withdpg.window(label=title, modal=True, no_close=True) asmodal_id:
dpg.add_text(message)
dpg.add_button(label="Ok", width=75, user_data=(modal_id, True), callback=selection_callback)
dpg.add_same_line()
dpg.add_button(label="Cancel", width=75, user_data=(modal_id, False), callback=selection_callback)
# guarantee these commands happen in another framedpg.split_frame()
width=dpg.get_item_width(modal_id)
height=dpg.get_item_height(modal_id)
dpg.set_item_pos(modal_id, [viewport_width//2-width//2, viewport_height//2-height//2])
defon_selection(sender, unused, user_data):
ifuser_data[1]:
print("User selected 'Ok'")
else:
print("User selected 'Cancel'")
# delete windowdpg.delete_item(user_data[0])
withdpg.window(label="Example"):
dpg.add_button(label="Open Messagebox", callback=lambda:show_info("Message Box", "Do you wish to proceed?", on_selection))
dpg.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
There are several ways you could make your own message box. Most will follow a pattern similar to the example below. This example demonstrates a function that creates a centered modal popup window that is destroyed after the user makes a selection.
Example
Resources
Notes
split_frame()
added in 0.8.14Reusable Code
Beta Was this translation helpful? Give feedback.
All reactions