MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / update_animation_no_buffering

Method update_animation_no_buffering

PySimpleGUI/PySimpleGUI.py:5982–6033  ·  view source on GitHub ↗

Show an Animated GIF. Call the function as often as you like. The function will determine when to show the next frame and will automatically advance to the next frame at the right time. NOTE - does NOT perform a sleep call to delay :param source: Filename or Ba

(self, source, time_between_frames=0)

Source from the content-addressed store, hash-verified

5980
5981
5982 def update_animation_no_buffering(self, source, time_between_frames=0):
5983 """
5984 Show an Animated GIF. Call the function as often as you like. The function will determine when to show the next frame and will automatically advance to the next frame at the right time.
5985 NOTE - does NOT perform a sleep call to delay
5986
5987 :param source: Filename or Base64 encoded string containing Animated GIF
5988 :type source: str | bytes
5989 :param time_between_frames: Number of milliseconds to wait between showing frames
5990 :type time_between_frames: (int)
5991 :return: True if worked OK, False if out of frames, None is window was closed
5992 :rtype: True | False | None
5993 """
5994
5995 if self.Source != source:
5996 self.AnimatedFrames = None
5997 self.Source = source
5998 self.frame_num = 0
5999
6000 now = time.time()
6001
6002 if time_between_frames:
6003 if (now - self.LastFrameTime) * 1000 > time_between_frames:
6004 self.LastFrameTime = now
6005 else: # don't reshow the frame again if not time for new frame
6006 return True
6007
6008 # read a frame
6009 done = False
6010 while True:
6011 if type(source) is not bytes:
6012 try:
6013 self.image = tk.PhotoImage(file=source, format='gif -index %i' % (self.frame_num))
6014 self.frame_num += 1
6015 except Exception as e:
6016 self.frame_num = 0
6017 done = True
6018 else:
6019 try:
6020 self.image = tk.PhotoImage(data=source, format='gif -index %i' % (self.frame_num))
6021 self.frame_num += 1
6022 except:
6023 self.frame_num = 0
6024 done = True
6025
6026 if self.frame_num:
6027 break
6028
6029 try: # needed in case the window was closed with an "X"
6030 self.tktext_label.configure(image=self.image, width=self.image.width(), heigh=self.image.height())
6031 except:
6032 done = None
6033 return not done
6034
6035 Update = update
6036 UpdateAnimation = update_animation

Callers 2

popup_animatedFunction · 0.80
mainFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected