-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWidgets_Selectables.py
60 lines (40 loc) · 1.92 KB
/
Widgets_Selectables.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import dearpygui.dearpygui as dpg
import dearpygui.demo as demo
def _config(sender, keyword, user_data):
widget_type = dpg.get_item_type(sender)
items = user_data
if widget_type == "mvAppItemType::mvRadioButton":
value = True
else:
keyword = dpg.get_item_label(sender)
value = dpg.get_value(sender)
if isinstance(user_data, list):
for item in items:
dpg.configure_item(item, **{keyword: value})
else:
dpg.configure_item(items, **{keyword: value})
dpg.create_context()
dpg.create_viewport(title='Custom Title', width=500, height=200)
with dpg.window(label="Example Window", width=500, height=200):
# with dpg.tree_node(label="Selectables"):
with dpg.tree_node(label="Basic",default_open = True):
dpg.add_selectable(label="1. I am selectable")
dpg.add_text("2. I am not selectable")
with dpg.tree_node(label="Selection State: Single",default_open = True):
def _selection(sender, app_data, user_data):
for item in user_data:
if item != sender:
dpg.set_value(item, False)
items = (
dpg.add_selectable(label="1. I am selectable"),
dpg.add_selectable(label="2. I am selectable"),
dpg.add_selectable(label="3. I am selectable"),
dpg.add_selectable(label="4. I am selectable"),
dpg.add_selectable(label="5. I am selectable"),
)
for item in items:
dpg.configure_item(item, callback=_selection, user_data=items)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()