-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtab_bar_callback.py
More file actions
34 lines (29 loc) · 1.12 KB
/
tab_bar_callback.py
File metadata and controls
34 lines (29 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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()