이미지
📌 PhotoImage( [경로] )
: 경로에 위치한 이미지 객체 반환.
📌 Label( [윈도우] , image=[이미지 객체] )
: Label에 이미지 띄움.
📄 이미지 경로 입력해 이비지 바꾸는 프로그램.
from tkinter import *
def change_img():
path = input_box.get() # input_box에 입력된 경로 값 가져옴.
img = PhotoImage(file=path) # 해당 경로에 있는 이미지 받음.
image_label.config(image=img) # 이미지 변경.
image_label.image = img
window = Tk()
window.title("이미지")
photo = PhotoImage(file="짱구.gif") # 디폴트 이미지 파일 설정.
image_label = Label(window, image=photo)
image_label.pack()
input_box = Entry(window)
input_box.pack()
button = Button(window, text='이미지 변경', command=change_img)
button.pack()
window.mainloop()
'Python > GUI' 카테고리의 다른 글
[Python/GUI] 배치 관리자 (0) | 2022.10.14 |
---|---|
[Python] Button, Label, Entry (0) | 2022.10.14 |
[Python/GUI] tkinter (0) | 2022.10.14 |
댓글