From 217589c5a39ed41abdf53cb1860fe2365394b357 Mon Sep 17 00:00:00 2001 From: sara Date: Mon, 6 Dec 2021 19:38:41 +0100 Subject: An GUI weitergearbeitet --- src/gui/test.py | 71 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 33 deletions(-) (limited to 'src/gui/test.py') diff --git a/src/gui/test.py b/src/gui/test.py index 7ba928b..f3accf3 100644 --- a/src/gui/test.py +++ b/src/gui/test.py @@ -1,35 +1,40 @@ import dearpygui.dearpygui as dpg -dpg.create_context() - -with dpg.window(label="Tutorial", pos=(20, 50), width=275, height=225) as win1: - t1 = dpg.add_input_text(default_value="some text") - t2 = dpg.add_input_text(default_value="some text") - with dpg.child_window(height=100): - t3 = dpg.add_input_text(default_value="some text") - dpg.add_input_int() - dpg.add_input_text(default_value="some text") - -with dpg.window(label="Tutorial", pos=(320, 50), width=275, height=225) as win2: - dpg.add_input_text(default_value="some text") - dpg.add_input_int() - -with dpg.theme() as container_theme: - - with dpg.theme_component(dpg.mvAll): - dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (150, 100, 100), category=dpg.mvThemeCat_Core) - dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core) - - with dpg.theme_component(dpg.mvInputInt): - dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (100, 150, 100), category=dpg.mvThemeCat_Core) - dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core) - -dpg.bind_item_theme(win1, container_theme) - -dpg.show_style_editor() - -dpg.create_viewport(title='Custom Title', width=800, height=600) -dpg.setup_dearpygui() -dpg.show_viewport() -dpg.start_dearpygui() -dpg.destroy_context() +# Callbacks +def cb_nextpic(sender, app_data, user_data): + dpg.set_value(texture_id, user_data['textures'][user_data['next_key']]) + + # Set key for next Image. Rotate back to 1 when last image has been shown + if user_data['next_key'] < 11: + user_data['next_key'] = user_data['next_key']+1 + else: + user_data['next_key'] = 1 + + +# Load in the Logo and add it to the texture_registry +# TODO: Find out, what that thing is actually doing. It is not really clear atm. +width, height, channels, data = dpg.load_image("logo.png") +with dpg.texture_registry(): + texture_id = dpg.add_dynamic_texture(width, height, data) + +# Next, load in the rest of the pictures +# Important: We are only interested in the data part here! +# Important: All the images must have the same size, because they are +# displayed on the image that will be created from the +# texture_id of the registry +img_dict = {} +for a in range(11): + width, height, channels, data = dpg.load_image(f"resources\img{a+1}.png") + img_dict[a+1] = data + +img_handler_dict = { + 'next_key': 1, + 'textures': img_dict +} + +with dpg.window(label="Hangman") as main_window: + dpg.add_image(texture_id) + dpg.add_button(label="Next IMG", callback=cb_nextpic, user_data=img_handler_dict) + +dpg.set_primary_window(main_window, True) +dpg.start_dearpygui() \ No newline at end of file -- cgit v1.2.1