-
Notifications
You must be signed in to change notification settings - Fork 0
/
photos.py
32 lines (32 loc) · 996 Bytes
/
photos.py
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
import io
import os
import PySimpleGUI as sg
from PIL import Image
file_types = [("JPEG (*.jpg)", "*.jpg"),
("All files (*.*)", "*.*")]
def main():
layout = [
[sg.Image(key="-IMAGE-")],
[
sg.Text("Image File"),
sg.Input(size=(150, 1), key="-FILE-"),
sg.FileBrowse(file_types=file_types),
sg.Button("Load Image"),
],
]
window = sg.Window("Image Viewer", layout)
while True:
event, values = window.read()
if event == "Exit" or event == sg.WIN_CLOSED:
break
if event == "Load Image":
filename = values["-FILE-"]
if os.path.exists(filename):
image = Image.open(values["-FILE-"])
image.thumbnail((400, 400))
bio = io.BytesIO()
image.save(bio, format="PNG")
window["-IMAGE-"].update(data=bio.getvalue())
window.close()
if __name__ == "__main__":
main()