반응형
import os
path = os.path.join("이미지 경로")
file_list = os.listdir(path)
def read_img(file_path):
img = Image.open(file_path)
if img.size[0] > 1000 or img.size[1] > 1000:
img = img.resize((int(img.width / 2), int(img.height / 2)))
return img
# jpg 리스트로 이미지 열기 + 다음버튼까지
def forward(image_number):
global label
global button_forward
global button_back
label.grid_forget()
label = Label(image=img_list[image_number-1])
button_forward = Button(window, text=">>", command=lambda : forward(image_number+1))
button_back = Button(window, text="<<", command=lambda : back(image_number-1))
# if image_number == len(img_list):
if image_number == len(img_list[:5]):
button_forward = Button(window, text=">>", state=DISABLED)
label.grid(row=0, column=0, columnspan=3)
button_back.grid(row=1, column=0)
button_forward.grid(row=1, column=2)
def back(image_number):
global label
global button_forward
global button_back
label.grid_forget()
label = Label(image=img_list[image_number-1])
button_forward = Button(window, text=">>", command=lambda : forward(image_number+1))
button_back = Button(window, text="<<", command=lambda: back(image_number-1))
if image_number ==1:
button_back = Button(window, text="<<", state = DISABLED)
label.grid(row=0, column=0, columnspan=3)
button_back.grid(row=1, column=0)
button_forward.grid(row=1, column=2)
from tkinter import *
from PIL import ImageTk,Image
window = Tk()
window.config(padx=10, pady=10)
window.title("수정 툴")
canvas = Canvas(window)
canvas.grid(column=0, row=1, columnspan=2)
img_list = []
for file in file_list[:5]:
file_path = path + file
img = read_img(file_path)
img_list.append(ImageTk.PhotoImage(img))
img_num = 0
label = Label(image = img_list[img_num])
label.grid(row=0, column=0, columnspan=3)
button_forward = Button(window, text=">>", command=lambda : forward(2))
# button_forward.grid(row=5, column=0)
button_forward.grid(row=1, column=2)
window.mainloop()
반응형
'-------------코딩------------- > Python(tkinter)' 카테고리의 다른 글
tkinter 좌표 찾기 (0) | 2022.08.01 |
---|---|
tkinter 그림그리기 (0) | 2022.08.01 |
tkinter 메뉴바 (0) | 2022.08.01 |
tkinter 버튼 그리기 (0) | 2022.08.01 |
댓글