Issue
Using pySimpleGUI I simply want to change the mouse cursor while the code is processing a query, but the cursor does only change after the code is executed... it does work when I put a window.read() after the set_cursor() call, but then the proceeding code is not executed immediately. What am I doing wrong? Unfortunately, the documentation does not provide an example.
import PySimpleGUI as sg
#... more code
window = sg.Window(f"Report Generator v{APP_VERSION}", layout)
while True:
event, values = window.read()
# close button was clicked
if event == "Close" or event == sg.WIN_CLOSED:
break
# Generate button was clicked
elif event == "Generate":
window.set_cursor("coffee_mug")
window.refresh()
# more code where the cursor should be changed but isn't
Solution
Not completely sure why is that, but the following works as desired. The crucial part is to add the Submit button ID at the window['Submit'].set_cursor("coffee_mug")
, then the new cursor is displayed before the next code is executed. And it will also show the new cursor at the entire window, not only when hovering over the button as one might have expected:
import PySimpleGUI as sg
layout = [
[sg.Text("Hello World")],
[sg.Button('Submit'), sg.Button('Cancel')],
]
window = sg.Window(f"Report Generator v{APP_VERSION}", layout)
while True:
event, values = window.read()
# close button was clicked
if event == "Close" or event == sg.WIN_CLOSED:
break
# Generate button was clicked
elif event == "Submit":
window['Submit'].set_cursor("coffee_mug")
time.sleep(5)
# more code where the cursor should be changed but isn't
Answered By - Boketto
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.