반응형
1. hello_world.py
import PySimpleGUI as sg
sg.Window(title="Hello World", layout=[[]], margins=(100,50)).read()
2. hello_psg.py
import PySimpleGUI as sg
layout = [
[sg.Text("Hello from PySimpleGUI")],
[sg.Button("OK")]
]
window = sg.Window("Demo", layout)
while True:
event, values = window.read()
if event =="OK" or event == sg.WIN_CLOSED:
break
window.close()
3. Image_Viewer.py
import PySimpleGUI as sg
import os.path
file_list_column = [
[
sg.Text("Image Folder"),
sg.In(size=(25,1), enable_events=True, key="-FOLDER-"),
sg.FolderBrowse(),
],
[
sg.Listbox(
values=[], enable_events=True, size=(40, 20),
key="-FILE LIST-"
)
],
]
image_viewer_column = [
[sg.Text("Choose an image from the list on the left:")],
[sg.Text(size=(40,1), key="-TOUT-")],
[sg.Image(key="-IMAGE-")],
]
layout = [
[
sg.Column(file_list_column),
sg.VSeperator(),
sg.Column(image_viewer_column),
]
]
window = sg.Window("Image Viewer", layout)
while True:
event, values = window.read()
if event =="Exit" or event == sg.WINDOW_CLOSED:
break
if event == "-FOLDER-":
folder = values["-FOLDER-"]
try:
file_list = os.listdir(folder)
except:
file_list = []
fnames = [
f
for f in file_list
if os.path.isfile(os.path.join(folder, f))
and f.lower().endswith((".png", ".gif"))
]
window["-FILE LIST-"].update(fnames)
elif event == "-FILE LIST-":
try:
filename = os.path.join(
values["-FOLDER-"], values["-FILE LIST-"][0]
)
window["-TOUT-"].update(filename)
window["-IMAGE-"].update(filename=filename)
except:
pass
window.close()
<결과>
반응형
'Programming > Python_Etc' 카테고리의 다른 글
파이썬 kivy 시작하기 1 - Kivy란? (0) | 2021.09.24 |
---|---|
파이썬 tkinter 로 만드는 PDF 텍스트 추출 프로그램 (0) | 2021.09.23 |
파이썬 주피터 노트북 Extension 설치 (0) | 2021.09.15 |
Python folium을 이용한 지도 불러오기 / 마커 표시하기 (0) | 2021.09.05 |
Python - 엑셀 자료 분석(셀 참조 with xlwings) (0) | 2021.02.04 |