From bf687f114d916c4fa2ee13fbb4ef1ea8fb4ed79b Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Sun, 21 Jun 2020 08:48:56 -0400 Subject: [PATCH 1/2] Make sure bar is behind the text --- DemoPrograms/Demo_Desktop_Widget_CPU_Square.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/DemoPrograms/Demo_Desktop_Widget_CPU_Square.py b/DemoPrograms/Demo_Desktop_Widget_CPU_Square.py index ace0eb35..36b9e9b4 100644 --- a/DemoPrograms/Demo_Desktop_Widget_CPU_Square.py +++ b/DemoPrograms/Demo_Desktop_Widget_CPU_Square.py @@ -35,19 +35,22 @@ text_id2 = graph.draw_text(f'CPU', (GSIZE[0] // 2, GSIZE[1] // 4), font='Any 20' while True: # Event Loop # ----------- update the graphics and text in the window ------------ cpu_percent = psutil.cpu_percent(interval=1) - + # Draw the filled rectangle rect_height = int(GSIZE[1] * float(cpu_percent) / 100) rect_id = graph.draw_rectangle((0, rect_height), (GSIZE[0], 0), fill_color=sg.theme_button_color()[1], line_width=0) - text_id1 = graph.draw_text(f'{int(cpu_percent)}%', (GSIZE[0] // 2, GSIZE[1] // 2), font='Any 40', text_location=sg.TEXT_LOCATION_CENTER, - color=sg.theme_button_color()[0]) + # Draw the % used text and the close "X" on bottom text_id3 = graph.draw_text('❎', (0, 0), font='Any 8', text_location=sg.TEXT_LOCATION_BOTTOM_LEFT, color=sg.theme_button_color()[0]) + # put the bar behind everything else + graph.send_figure_to_back(rect_id) + # update the window, wait for a while, then check for exit event, values = window.read(timeout=UPDATE_FREQUENCY_MILLISECONDS) if event == sg.WIN_CLOSED or event == 'Exit': break if event == '-GRAPH-': # exit if clicked in the bottom left 20 x 20 pixel area if values['-GRAPH-'][0] < 20 and values['-GRAPH-'][1] < 20: break + # erase figures so they can be redrawn graph.delete_figure(rect_id) graph.delete_figure(text_id1) graph.delete_figure(text_id3) From ed0fd5fbbb7d612a1c6bcb7ddc99e03e7460b7a1 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Sun, 21 Jun 2020 08:51:42 -0400 Subject: [PATCH 2/2] Code cleanup --- DemoPrograms/Demo_Desktop_Widget_CPU_Square.py | 1 + 1 file changed, 1 insertion(+) diff --git a/DemoPrograms/Demo_Desktop_Widget_CPU_Square.py b/DemoPrograms/Demo_Desktop_Widget_CPU_Square.py index 36b9e9b4..21f27eea 100644 --- a/DemoPrograms/Demo_Desktop_Widget_CPU_Square.py +++ b/DemoPrograms/Demo_Desktop_Widget_CPU_Square.py @@ -39,6 +39,7 @@ while True: # Event Loop rect_height = int(GSIZE[1] * float(cpu_percent) / 100) rect_id = graph.draw_rectangle((0, rect_height), (GSIZE[0], 0), fill_color=sg.theme_button_color()[1], line_width=0) # Draw the % used text and the close "X" on bottom + text_id1 = graph.draw_text(f'{int(cpu_percent)}%', (GSIZE[0] // 2, GSIZE[1] // 2), font='Any 40', text_location=sg.TEXT_LOCATION_CENTER, color=sg.theme_button_color()[0]) text_id3 = graph.draw_text('❎', (0, 0), font='Any 8', text_location=sg.TEXT_LOCATION_BOTTOM_LEFT, color=sg.theme_button_color()[0]) # put the bar behind everything else graph.send_figure_to_back(rect_id)