Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

[ Enhancement] Propagate exceptions on update_animation(self, source, time_between_frames=0)

Ouverte
#6,447 5 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
35/100
Type d'issue
Fonctionnalité
Clarté
Clairement spécifiée
Activité
À l'abandon
Stack technique
python
Domaine
desktop

Piste de recherche

Commencez dans PySimpleGUI.py, au niveau de la classe Image et de update_animation, en particulier dans la boucle de chargement des frames animées et sa gestion des exceptions. Exécutez le reproducteur threading fourni pour observer le chemin d’erreur actuel. C’est terminé lorsque l’exception tkinter sous-jacente est propagée au lieu d’être masquée par la logique de chargement des frames.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Bug Port - TK
Enhancement

Operating System

Windows

PySimpleGUI Port (tkinter, Qt, Wx, Web)

tkinter


Versions

PySimpleGUI long version = 4.59.0 Released 5-Apr-2022
PySimpleGUI Version 4.59.0
tcl ver = 8.6 tkinter version = 8.6
Python Version 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)]
tcl detailed version = 8.6.12

Your Experience In Months or Years (optional)

Years Python programming experience 2

Years Programming experience overall 8

Have used another Python GUI Framework? no

Anything else you think would be helpful?


Troubleshooting

These items may solve your problem. Please check those you've done by changing - [ ] to - [X]

  • Searched main docs for your problem www.PySimpleGUI.org
  • Looked for Demo Programs that are similar to your goal. It is recommend you use the Demo Browser! Demos.PySimpleGUI.org
  • None of your GUI code was generated by an AI algorithm like GPT
  • If not tkinter - looked for Demo Programs for specific port
  • For non tkinter - Looked at readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • Run your program outside of your debugger (from a command line)
  • Searched through Issues (open and closed) to see if already reported Issues.PySimpleGUI.org
  • Have upgraded to the latest release of PySimpleGUI on PyPI (lastest official version)
  • Tried using the PySimpleGUI.py file on GitHub. Your problem may have already been fixed but not released
Detailed Description

Basically, the update_animation(...) method returns "Exception has occurred: ZeroDivisionError" when i run it on a different thread and that (at least for me) does not make any sense...the error description not the implementation.

Exception is generated here ( code from PySimpleGUI.py, class Image(Element), method update_animation ) :

if time_between_frames:
            if (now - self.LastFrameTime) * 1000 > time_between_frames:
                self.LastFrameTime = now
                self.CurrentFrameNumber = (self.CurrentFrameNumber + 1) % self.TotalAnimatedFrames
            else:  # don't reshow the frame again if not time for new frame
                return
        else:
            self.CurrentFrameNumber = (self.CurrentFrameNumber + 1) % self.TotalAnimatedFrames
        image = self.AnimatedFrames[self.CurrentFrameNumber]
        try:  # needed in case the window was closed with an "X"
            self.tktext_label.configure(image=image, width=image.width(), heigh=image.height())
        except Exception as e:
            print('Exception in update_animation', e)

at

self.CurrentFrameNumber = (self.CurrentFrameNumber + 1) % self.TotalAnimatedFrames

but actually it's a propagation of :

for i in range(1000):
                if type(source) is not bytes:
                    try:
                        self.AnimatedFrames.append(tk.PhotoImage(file=source, format='gif -index %i' % (i)))
                    except Exception as e:
                        break
                else:
                    try:
                        self.AnimatedFrames.append(tk.PhotoImage(data=source, format='gif -index %i' % (i)))
                    except Exception as e:
                        break

few lines higher.

The error comes from:

try:
                        self.AnimatedFrames.append(tk.PhotoImage(file=source, format='gif -index %i' % (i)))
                    except Exception as e:
                        break

and is tkinter telling me that:

RuntimeError('main thread is not in main loop')

That is way more explanatory.

My suggestion is that these kind of errors should be propagated all the way up instead of try/catch and hiding them.

Code To Duplicate

import PySimpleGUI as sg
from threading import Thread

global new_thr
new_thr=None


def launch_thr():
    new_thr = Thread(target=update_image, args=[working_window])
    new_thr.start()

def update_image(working_window,):
    while True:
        working_window["-IMAGE_GIF-"].update_animation(work_gif,  time_between_frames=250)

work_gif=r'GUI_Launcher\Images\work.gif'


test_in_progress=[
                            [sg.Text("Please be patient...", expand_x=True, expand_y=True, font="courier 13 bold")],
                            [sg.Image(source=work_gif, size=(375,375), key="-IMAGE_GIF-")],
                            [sg.Text("... I am working for you", expand_x=True, expand_y=True, font="courier 13 bold")]
                    ]

working_window = sg.Window("Test in progress", layout=test_in_progress, size=(800,600), return_keyboard_events=True, finalize=True)


while True:

    if new_thr is None:
        launch_thr()


    str="do stuff"

Screenshot, Sketch, or Drawing

Watcha Makin?

A gui to launch sessions of Robot Framework. This problem occured when i tried to implement an animation when tests are running.

Langage dominant
Python
Étoiles
13.8k
Forks
1.8k
Métriques de merge des PR
Aucune PR mergée en 30 j

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de PySimpleGUI/PySimpleGUI

Toutes les issues de PySimpleGUI/PySimpleGUI

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.