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
I'm making an on screen keyboard and I need to shift the middle row to the right by half the width of a key, so it could align properly.
I tried to do that with a spacer before the first key of the middle row, but I cannot change the width of the spacer either on creation or on runtime, it seems like the width argument of it is ignored.
What should I do instead to achieve this?
Thanks.
import dearpygui.dearpygui as dpg
dpg.create_context()
row0 = ['test', 'testing']
row1 = ['q','w','e','r','t','y','u','i','o','p']
row2 = ['a','s','d','f','g','h','j','k','l']
row3 = ['^','z','x','c','v','b','n','m','<']
row4 = ['More...',',',' Space ','.',' Enter ']
# set decorated for boarderless window
dpg.create_viewport(title='lightboard', width=600, height=200, decorated=True, resizable=True)
dpg.setup_dearpygui()
dpg.show_viewport()
with dpg.window(tag="Primary Window", no_scrollbar=True) as keyboardUI:
with dpg.group(horizontal=True) as krow0:
for i in range(0, len(row0)):
dpg.add_button(label=row0[i])
with dpg.group(horizontal=True) as krow1:
for i in range(0, len(row1)):
dpg.add_button(label=row1[i])
with dpg.group(horizontal=True) as krow2:
for i in range(0, len(row2)):
dpg.add_button(label=row2[i])
with dpg.group(horizontal=True) as krow3:
for i in range(0, len(row3)):
dpg.add_button(label=row3[i])
with dpg.group(horizontal=True) as krow4:
for i in range(0, len(row4)):
dpg.add_button(label=row4[i])
def resize_keyboardUI():
# find keyboard size
x,y = dpg.get_item_rect_size(keyboardUI)
y=y-35
x=x-100
dpg.set_item_height(krow0, y//5)
dpg.set_item_width(krow0, (x//len(row0)))
keywidth = (x//(len(row1)))
dpg.set_item_height(krow1, y//5)
dpg.set_item_width(krow1, keywidth)
dpg.set_item_height(krow2, y//5)
dpg.set_item_width(krow2, keywidth)
dpg.set_item_height(krow3, y//5)
dpg.set_item_width(krow3, keywidth)
dpg.set_item_height(krow4, y//5)
dpg.set_item_width(krow4, x//(len(row4)))
with dpg.item_handler_registry() as registry:
dpg.add_item_resize_handler(callback=resize_keyboardUI)
dpg.bind_item_handler_registry(keyboardUI, registry)
dpg.set_primary_window("Primary Window", True)
dpg.start_dearpygui()
dpg.destroy_context()
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm making an on screen keyboard and I need to shift the middle row to the right by half the width of a key, so it could align properly.
I tried to do that with a spacer before the first key of the middle row, but I cannot change the width of the spacer either on creation or on runtime, it seems like the width argument of it is ignored.
What should I do instead to achieve this?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions