-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
main : added some button examples and updated README
- Loading branch information
Showing
3 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import dearpygui.dearpygui as dpg | ||
dpg.create_context() | ||
|
||
with dpg.theme() as button_clicked_theme: | ||
with dpg.theme_component(): | ||
dpg.add_theme_color(dpg.mvThemeCol_Button, (255, 0, 0)) | ||
dpg.add_theme_color(dpg.mvThemeCol_ButtonHovered, (225, 0, 0)) | ||
dpg.add_theme_color(dpg.mvThemeCol_ButtonActive, (205, 0, 0)) | ||
|
||
|
||
def toggle_button_colour(sender): | ||
if dpg.get_item_theme(sender) == button_clicked_theme: | ||
dpg.bind_item_theme(sender, None) | ||
else: | ||
dpg.bind_item_theme(sender, button_clicked_theme) | ||
|
||
with dpg.window(): | ||
dpg.add_button(label="Click me!", callback=toggle_button_colour) | ||
|
||
|
||
dpg.create_viewport(width=800, height=600, title="Change button colour when clicked") | ||
dpg.setup_dearpygui() | ||
dpg.show_viewport() | ||
dpg.start_dearpygui() | ||
dpg.destroy_context() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import dearpygui.dearpygui as dpg | ||
dpg.create_context() | ||
|
||
buttons = { | ||
"1": {"checked": True, "nested": {"1a":False, "1b":True, "1c":False, "1d":False}}, | ||
"2": {"checked": False, "nested": {}}, | ||
"3": {"checked": False, "nested": {"3a":True}}, | ||
} | ||
|
||
def checkbox_callback(sender): | ||
for button in buttons.keys(): | ||
if not button == sender: | ||
buttons[button]["checked"] = False | ||
dpg.set_value(button, False) | ||
else: | ||
buttons[button]["checked"] = True | ||
if not dpg.get_value(sender): | ||
dpg.set_value(sender, True) | ||
|
||
def radio_button_callback(sender): | ||
for nested_button in buttons[sender.split("_")[0]]["nested"].keys(): | ||
buttons[sender.split("_")[0]]["nested"][nested_button] = False | ||
buttons[sender.split("_")[0]]["nested"][dpg.get_value(sender)] = True | ||
|
||
with dpg.window(): | ||
for button, values in buttons.items(): | ||
dpg.add_checkbox( | ||
tag=button, | ||
label=button, | ||
default_value=values["checked"], | ||
callback=checkbox_callback, | ||
) | ||
if values["nested"]: | ||
dpg.add_radio_button( | ||
tag=button + "_nested", | ||
items=list(values["nested"].keys()), | ||
indent=24, | ||
callback=radio_button_callback, | ||
) | ||
for nested_button, nested_values in values["nested"].items(): | ||
if nested_values: | ||
dpg.set_value(button + "_nested", nested_button) | ||
|
||
dpg.add_spacer(height=20) | ||
dpg.add_button(label="Print buttons state", callback=lambda: print(buttons)) | ||
|
||
|
||
dpg.create_viewport(width=800, height=600, title="Nested Radio Buttons Demo") | ||
dpg.setup_dearpygui() | ||
dpg.show_viewport() | ||
dpg.start_dearpygui() | ||
dpg.destroy_context() |