Python Forum
PySimpleGUI Try Except
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PySimpleGUI Try Except
#1
Hi all,

I'm trying to get my program to try to make a layout with an sg.Image element, however the file path is a variable so it can update the image in the window based on the user input. However I need a way that it doesn't crash when the image isnt in the folder. I've tried putting try and except statements in several places but wondered if there's another way?

Thanks,
James
while dad_has_cigs == True:
    happiness = True
    if dad_has_cigs == False:
    print("Dad come home!")
    happiness = not happiness
    break
Reply
#2
Hi all,

I found the solution in the end :

try:
    imageView['imageview'].update(filename = (r'your path\\yourimage'+".jpg"))
                            
    while True:             
        event,values = imageView.read()
        if event == sg.WIN_CLOSED:
            break
except:
        sg.popup("Image not found")
while dad_has_cigs == True:
    happiness = True
    if dad_has_cigs == False:
    print("Dad come home!")
    happiness = not happiness
    break
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020