From 3b00016ddb8da293bf31876db95afe96962b5d26 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Fri, 2 Jul 2021 15:04:30 -0400 Subject: [PATCH 1/2] Renamed the cursor demo. Included example of turning off the cursor entirely at the element and the window level. --- DemoPrograms/Demo_Cursor_Changed_To_Hand.py | 42 ---------------- DemoPrograms/Demo_Cursors.py | 53 +++++++++++++++++++++ 2 files changed, 53 insertions(+), 42 deletions(-) create mode 100644 DemoPrograms/Demo_Cursors.py diff --git a/DemoPrograms/Demo_Cursor_Changed_To_Hand.py b/DemoPrograms/Demo_Cursor_Changed_To_Hand.py index 61da1d6f..8b137891 100644 --- a/DemoPrograms/Demo_Cursor_Changed_To_Hand.py +++ b/DemoPrograms/Demo_Cursor_Changed_To_Hand.py @@ -1,43 +1 @@ -import PySimpleGUI as sg -import webbrowser -""" - Demonstration of setting an Element's Widget to use a different cursor than the - standard arrow. In this case, the cursor is changed into a hand when hovering over the Text Element. - - This implementation relies on accessing the underlying tkinter widget to change the cursor as there is currently no method provided for you to modify a widget's cursor. Accessing an Element's tkinter widget is easy and straightforward, you simply write: - window[key].Widget -""" - -# Here is a more complete list of cursors you can choose from -cursors = ('X_cursor', 'no', 'arrow','based_arrow_down','based_arrow_up','boat','bogosity','bottom_left_corner','bottom_right_corner','bottom_side','bottom_tee','box_spiral','center_ptr','circle','clock','coffee_mug','cross','cross_reverse','crosshair','diamond_cross','dot','dotbox','double_arrow','draft_large','draft_small','draped_box','exchange','fleur','gobbler','gumby','hand1','hand2','heart','icon','iron_cross','left_ptr','left_side','left_tee','leftbutton','ll_angle','lr_angle','man','middlebutton','mouse','no','pencil','pirate','plus','question_arrow','right_ptr','right_side','right_tee','rightbutton','rtl_logo','sailboat','sb_down_arrow','sb_h_double_arrow','sb_left_arrow','sb_right_arrow','sb_up_arrow','sb_v_double_arrow','shuttle','sizing','spider','spraycan','star','target','tcross','top_left_arrow','top_left_corner','top_right_corner','top_side','top_tee','trek','ul_angle','umbrella','ur_angle','watch','xterm','arrow','center_ptr','crosshair','fleur','ibeam','icon','sb_h_double_arrow','sb_v_double_arrow','watch','xterm','no','starting','size','size_ne_sw','size_ns','size_nw_se','size_we','uparrow','wait','arrow','cross','crosshair','ibeam','plus','watch','xterm') - -sg.theme('Light Blue 2') - -layout = [ [sg.Text('Here is a clickable link for you')], - [sg.Text('Notice how the cursor switches to a "hand" when hover over the link')], - [sg.Text('www.PySimpleGUI.org', font=('default 12 underline'), text_color='blue', enable_events=True, key='-LINK-')], - [sg.Text('Try out these additional cursors')], - [sg.Text('watch - This makes the spinning-donut-of-death cursor on Windows', key='-WATCH-')], - [sg.Text('fleur - The "Move" cursor', key='-FLEUR-')], - [sg.Text('trek - Beam me up Scotty!', key='-TREK-')], - [sg.Button('Exit')] ] - -window = sg.Window('Window Title', layout, finalize=True) - -# Directly interact with the tkinter widget, changing the cursor shown when placed cursor is over this element -window['-LINK-'].set_cursor(cursor='hand2') -window['-WATCH-'].set_cursor(cursor='watch') -window['-FLEUR-'].set_cursor(cursor='fleur') -window['-TREK-'].set_cursor(cursor='trek') -window['Exit'].set_cursor(cursor='no') - -while True: # Event Loop - event, values = window.read() - print(event, values) - if event in (sg.WIN_CLOSED, 'Exit'): - break - if event == '-LINK-': - # if the text was clicked, open a browser using the text as the address - webbrowser.open(window['-LINK-'].DisplayText) # accessing DisplayText isn't something you'll see often -window.close() diff --git a/DemoPrograms/Demo_Cursors.py b/DemoPrograms/Demo_Cursors.py new file mode 100644 index 00000000..e050022e --- /dev/null +++ b/DemoPrograms/Demo_Cursors.py @@ -0,0 +1,53 @@ +import PySimpleGUI as sg +import webbrowser + +""" + Demo Cursors + + Demonstration of setting an Element's Cursor to use a different cursor than the standard arrow. + Can also change Cursor at the Window level. + + If you want no cursor, set the cursor to the string 'none'. + + Copyright 2021 PySimpleGUI +""" + +# Here is a more complete list of cursors you can choose from +cursors = ('X_cursor', 'no', 'arrow','based_arrow_down','based_arrow_up','boat','bogosity','bottom_left_corner','bottom_right_corner','bottom_side','bottom_tee','box_spiral','center_ptr','circle','clock','coffee_mug','cross','cross_reverse','crosshair','diamond_cross','dot','dotbox','double_arrow','draft_large','draft_small','draped_box','exchange','fleur','gobbler','gumby','hand1','hand2','heart','icon','iron_cross','left_ptr','left_side','left_tee','leftbutton','ll_angle','lr_angle','man','middlebutton','mouse','no','pencil','pirate','plus','question_arrow','right_ptr','right_side','right_tee','rightbutton','rtl_logo','sailboat','sb_down_arrow','sb_h_double_arrow','sb_left_arrow','sb_right_arrow','sb_up_arrow','sb_v_double_arrow','shuttle','sizing','spider','spraycan','star','target','tcross','top_left_arrow','top_left_corner','top_right_corner','top_side','top_tee','trek','ul_angle','umbrella','ur_angle','watch','xterm','arrow','center_ptr','crosshair','fleur','ibeam','icon','sb_h_double_arrow','sb_v_double_arrow','watch','xterm','no','starting','size','size_ne_sw','size_ns','size_nw_se','size_we','uparrow','wait','arrow','cross','crosshair','ibeam','plus','watch','xterm') + +sg.theme('Light Blue 2') + +layout = [ [sg.Text('Here is a clickable link for you')], + [sg.Text('Notice how the cursor switches to a "hand" when hover over the link')], + [sg.Text('www.PySimpleGUI.org', font='default 12 underline', text_color='blue', enable_events=True, key='-LINK-')], + [sg.Text('Try out these additional cursors')], + [sg.Text('watch - This makes the spinning-donut-of-death cursor on Windows', key='-WATCH-')], + [sg.Text('fleur - The "Move" cursor', key='-FLEUR-')], + [sg.Text('trek - Beam me up Scotty!', key='-TREK-')], + [sg.Text('none - No cursor at all', key='-NONE-')], + [sg.Text('For touchscreen applications, you may want to turn off the cursor entirely for the windw')], + [sg.Text('Click the Hide Cursor button to turn off at the Window level.')], + [sg.Text('Elements that have specific cursors set will continue to show those cursors')], + [sg.Button('Hide Cursor'), sg.Button('Exit')] ] + +window = sg.Window('Cursor Demo', layout, finalize=True) + +# Make sure window is finalized first. Then set the cursor +window['-LINK-'].set_cursor(cursor='hand1') +window['-WATCH-'].set_cursor(cursor='watch') +window['-FLEUR-'].set_cursor(cursor='fleur') +window['-TREK-'].set_cursor(cursor='trek') +window['Exit'].set_cursor(cursor='no') +window['-NONE-'].set_cursor(cursor='none') + +while True: # Event Loop + event, values = window.read() + print(event, values) + if event in (sg.WIN_CLOSED, 'Exit'): + break + elif event == 'Hide Cursor': + window.set_cursor('none') # special value that hides the cursor entirely + elif event == '-LINK-': + # if the text was clicked, open a browser using the text as the address + webbrowser.open(window['-LINK-'].DisplayText) # accessing DisplayText isn't something you'll see often +window.close() \ No newline at end of file From 49bb18e496f084c8b34ca6292ddc4edd68f94f8b Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Fri, 2 Jul 2021 15:04:44 -0400 Subject: [PATCH 2/2] Delete Demo_Cursor_Changed_To_Hand.py --- DemoPrograms/Demo_Cursor_Changed_To_Hand.py | 1 - 1 file changed, 1 deletion(-) delete mode 100644 DemoPrograms/Demo_Cursor_Changed_To_Hand.py diff --git a/DemoPrograms/Demo_Cursor_Changed_To_Hand.py b/DemoPrograms/Demo_Cursor_Changed_To_Hand.py deleted file mode 100644 index 8b137891..00000000 --- a/DemoPrograms/Demo_Cursor_Changed_To_Hand.py +++ /dev/null @@ -1 +0,0 @@ -