You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It takes a lot of effort to align text to the right when using add_text. Text can be aligned on buttons, so it seems not too far-fetched to be able to specify alignment for add_text. Aligning numbers to the right is very useful for presenting data and financial information.
The text can be aligned on buttons and, with a bit of trickery, the fact that it's a button can be hidden, so that you end up with the following output.
Code for creating the example above.
importdearpygui.dearpyguiasdpgBACKGROUND_COLOUR= (0,0,0)
withdpg.window(label="tutorial") asmain_window:
button1=dpg.add_button(label="1.000,34", width=200)
button2=dpg.add_button(label="75,23", width=200)
button3=dpg.add_button(label="758,11", width=200)
button4=dpg.add_button(label="---------", width=200)
button5=dpg.add_button(label="1.833,68", width=200)
# create a button themewithdpg.theme() asbutton_right:
# set text alignment on button to align to the rightdpg.add_theme_style(dpg.mvStyleVar_ButtonTextAlign, 1.00, category=dpg.mvThemeCat_Core)
# set the colour of all states of a button to the background colourdpg.add_theme_color(dpg.mvThemeCol_Button, BACKGROUND_COLOUR, category=dpg.mvThemeCat_Core)
dpg.add_theme_color(dpg.mvThemeCol_ButtonActive, BACKGROUND_COLOUR, category=dpg.mvThemeCat_Core)
dpg.add_theme_color(dpg.mvThemeCol_ButtonHovered, BACKGROUND_COLOUR, category=dpg.mvThemeCat_Core)
# set the window background colourwithdpg.theme(default_theme=True) astheme_id:
dpg.add_theme_color(dpg.mvThemeCol_WindowBg,BACKGROUND_COLOUR, category=dpg.mvThemeCat_Core)
defrun():
dpg.set_item_type_theme(dpg.mvButton, button_right)
dpg.set_primary_window(main_window, True)
dpg.start_dearpygui()
if__name__=='__main__':
run()
It takes a lot of effort to align text to the right when using add_text. Text can be aligned on buttons, so it seems not too far-fetched to be able to specify alignment for add_text. Aligning numbers to the right is very useful for presenting data and financial information.
The text can be aligned on buttons and, with a bit of trickery, the fact that it's a button can be hidden, so that you end up with the following output.
Code for creating the example above.
Related to #1057 but with 2 main differences:
Aligning text may not be as cool as 3D widgets, but very useful nonetheless 😉
The text was updated successfully, but these errors were encountered: