Skip to content

Commit

Permalink
main : added menubar examples
Browse files Browse the repository at this point in the history
  • Loading branch information
my1e5 committed Mar 13, 2023
1 parent 66109aa commit b260519
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
25 changes: 25 additions & 0 deletions menubar/menubar_right_aligned.py
Original file line number Diff line number Diff line change
@@ -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()
28 changes: 28 additions & 0 deletions menubar/menubar_types.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit b260519

Please sign in to comment.