From b2605195ca61e0e5ee5e78841f5d3564daeab093 Mon Sep 17 00:00:00 2001 From: my1e5 <10064103+my1e5@users.noreply.github.com> Date: Mon, 13 Mar 2023 17:19:14 +0000 Subject: [PATCH] main : added menubar examples --- README.md | 5 +++++ menubar/menubar_right_aligned.py | 25 +++++++++++++++++++++++++ menubar/menubar_types.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 menubar/menubar_right_aligned.py create mode 100644 menubar/menubar_types.py diff --git a/README.md b/README.md index a9aece3..247e737 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ A collection of example scripts which demonstrate various features/functionality - [Drawing](#drawing) - [Simple paint](#simple-paint) - [Listbox](#listbox) +- [Menubar](#menubar) - [Misc](#misc) - [Persistance](#persistance) - [Plots](#plots) @@ -40,6 +41,10 @@ A very simple implementation of a paint app. It demonstrates how you can click a Examples of custom listbox widgets which extend the functionality of the default listbox. Includes how to implement a listbox which is unselected by default and how to respond to key presses. +## [Menubar](menubar/) + +Examples of how to implement all the different types of menubar and how to implement a right-aligned menubar. + ## [Misc](misc/) Miscellaneous examples. diff --git a/menubar/menubar_right_aligned.py b/menubar/menubar_right_aligned.py new file mode 100644 index 0000000..0c5dd61 --- /dev/null +++ b/menubar/menubar_right_aligned.py @@ -0,0 +1,25 @@ +import dearpygui.dearpygui as dpg +dpg.create_context() + +with dpg.window(width=500, height=500, min_size=(200,200)) as window: + with dpg.menu_bar(): + spacer = dpg.add_spacer() + with dpg.menu(label="File"): + dpg.add_menu_item(label="New") + with dpg.menu(label="Edit"): + dpg.add_menu_item(label="Copy") + with dpg.menu(label="View"): + dpg.add_menu_item(label="Maximize") + +def adjust_menu_bar_spacer(): + dpg.configure_item(spacer, width=dpg.get_item_width(window) - 150) # adjust 150 to fit your needs + +with dpg.item_handler_registry() as item_handler_registry: + dpg.add_item_resize_handler(callback=adjust_menu_bar_spacer) +dpg.bind_item_handler_registry(window, item_handler_registry) + +dpg.create_viewport(width=800, height=600, title="Menubar right aligned") +dpg.setup_dearpygui() +dpg.show_viewport() +dpg.start_dearpygui() +dpg.destroy_context() diff --git a/menubar/menubar_types.py b/menubar/menubar_types.py new file mode 100644 index 0000000..58b8413 --- /dev/null +++ b/menubar/menubar_types.py @@ -0,0 +1,28 @@ +import dearpygui.dearpygui as dpg +dpg.create_context() + +with dpg.viewport_menu_bar(): + with dpg.menu(label="File"): + dpg.add_menu_item(label="New") + dpg.add_menu_item(label="Edit") + dpg.add_menu_item(label="View") + +with dpg.window(menubar=True): + with dpg.menu_bar(): + with dpg.menu(label="File"): + dpg.add_menu_item(label="New") + dpg.add_menu_item(label="Edit") + dpg.add_menu_item(label="View") + + with dpg.child_window(width=200, height=200, menubar=True): + with dpg.menu_bar(): + with dpg.menu(label="File"): + dpg.add_menu_item(label="New") + dpg.add_menu_item(label="Edit") + dpg.add_menu_item(label="View") + +dpg.create_viewport(width=800, height=600, title="Menubar types") +dpg.setup_dearpygui() +dpg.show_viewport() +dpg.start_dearpygui() +dpg.destroy_context()