Skip to content

Commit

Permalink
added tab bar callback example and updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
my1e5 committed Mar 13, 2023
1 parent 8d1d3d7 commit e64fded
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# DearPyGui examples
A collection of example scripts which demonstrate various features/functionality in DearPyGui.

<img src=assets/gifs/simple_paint.gif width=50%/>
<img src=assets/gifs/progress_bar.gif width=50%/>
![Simple paint](assets/gifs/simple_paint.gif)
![Marker size](assets/gifs/marker_size.gif)
![Progress bar](assets/gifs/progress_bar.gif)

## Examples

Expand Down
Binary file added assets/gifs/marker_size.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions buttons/tab_bar_callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import dearpygui.dearpygui as dpg
dpg.create_context()

'''
If you use a callback in directly in dpg.tab_bar, e.g.
with dpg.tab_bar(tag='tab_bar', callback=tab_bar_callback):
then the callback is only called when the tab changes. If you want
it to be called whenever the tab bar is clicked, i.e. even when
clicking the same tab, then here is a workaround.
'''

def tab_bar_callback():
for child in dpg.get_item_children('tab_bar')[1]:
if dpg.is_item_hovered(child):
dpg.split_frame() # wait a frame for the tab to change
print(f"{dpg.get_value('tab_bar')} clicked!")

with dpg.window():
with dpg.tab_bar(tag='tab_bar'):
with dpg.tab(label="T1", tag='T1'):
dpg.add_button(label="button1")
with dpg.tab(label="T2", tag='T2'):
dpg.add_slider_double()
with dpg.tab(label="T3", tag="T3"):
pass

with dpg.handler_registry():
dpg.add_mouse_click_handler(button=0, callback=tab_bar_callback)

dpg.create_viewport(width=800, height=600, title="Tab bar callback")
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

0 comments on commit e64fded

Please sign in to comment.