FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
PySimpleGUI/DemoPrograms/Demo_Animated_GIFs_Using_PIL.py at master · PySimpleGUI/PySimpleGUI · GitHub
PySimpleGUI
/
PySimpleGUI
Public
Notifications
You must be signed in to change notification settings
Fork
1.8k
Star
13.8k
Code
Issues
708
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
PySimpleGUI
/
DemoPrograms
/
Demo_Animated_GIFs_Using_PIL.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (23 loc) · 1.42 KB
Breadcrumbs
PySimpleGUI
/
DemoPrograms
/
Demo_Animated_GIFs_Using_PIL.py
Copy path
File metadata and controls
35 lines (23 loc) · 1.42 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from
PIL
import
Image
,
ImageTk
,
ImageSequence
import
PySimpleGUI
as
sg
"""
Demo_Animated_GIFs_Using_PIL.py
You'll find other animated GIF playback demos for PySimpleGUI that use the tkinter built-in GIF parser.
That is how the built-in PySimpleGUI Image.update_animation is used.
If you want to do the GIF file parsing yourself using PIL and update your Image element yourself, then
this is one possible technique.
This particular demo will loop playing the GIF file over and over. To not loop, remove the while True statement.
Copyright 2018-2026 PySimpleGUI. All rights reserved.
"""
gif_filename
=
r'ExampleGIF.gif'
layout
=
[[
sg
.
Text
(
'Happy Thursday!'
,
background_color
=
'#A37A3B'
,
text_color
=
'#FFF000'
,
justification
=
'c'
,
key
=
'-T-'
,
font
=
(
"Bodoni MT"
,
40
))],
[
sg
.
Image
(
key
=
'-IMAGE-'
)]]
window
=
sg
.
Window
(
'Window Title'
,
layout
,
element_justification
=
'c'
,
margins
=
(
0
,
0
),
element_padding
=
(
0
,
0
),
finalize
=
True
)
window
[
'-T-'
].
expand
(
True
,
True
,
True
)
# Make the Text element expand to take up all available space
interframe_duration
=
Image
.
open
(
gif_filename
).
info
[
'duration'
]
# get how long to delay between frames
while
True
:
for
frame
in
ImageSequence
.
Iterator
(
Image
.
open
(
gif_filename
)):
event
,
values
=
window
.
read
(
timeout
=
interframe_duration
)
if
event
==
sg
.
WIN_CLOSED
:
exit
(
0
)
window
[
'-IMAGE-'
].
update
(
data
=
ImageTk
.
PhotoImage
(
frame
) )
Back
|
FazBrowse Home
|
New Git URL