PS 1117

12940 ワード

from tkinter import *
from tkinter.filedialog import * # 파일 입출력을 위한 모듈
from tkinter.simpledialog import * # 숫자나 문자를 입력받기 위한 모듈
from wand.image import * # GIF뿐만 아니라 JPG, PNG 같은 이미지를 모두 처리하기 위해 외부 라이브러리 이미지 매직 사용

# 함수 정의 부분, 각 메뉴를 선택할 때 실행될 함수 선언
def displayImage(img, width, height) :
    global window,canvas, paper, photo, photo2, oriX, oriY, newX, newY

    if canvas != None :
        canvas.destroy()
        
    canvas=Canvas(window, width=width, height=height, bg='#1B1B1B', highlightthickness=0)
    paper=PhotoImage(width=width, height=height)       

    blob=img.make_blob(format='png')
    paper.put(blob)
    
    canvas.create_image((width/2,height/2), image=paper, state="normal")
    
    canvas.place(x=(1280-width)/2,y=(720-height)/2)

    
                 
#모든 함수들이 공통적으로 사용할 변수 선언부
def func_open() :
    #전역변수
    global window,canvas, paper, photo, photo2, oriX, oriY
    readFp = askopenfilename(parent=window, filetypes=(("모든 그림 파일", "*.jpg;*.jpeg;*.bmp;*.png;*.tif;*.gif"),  ("모든 파일", "*.*") ))
    photo = Image(filename=readFp)
    oriX = photo.width
    oriY = photo.height
    photo2 = photo.clone()
    newX = photo2.width 
    newY = photo2.height
    displayImage(photo2, newX, newY)
    
    #파일을 열었을시 메뉴바 Tool 활성화
    fileMenu.entryconfigure("열기",state=NORMAL)
    mainMenu.entryconfigure("Tool",state=NORMAL)
    mainMenu.entryconfigure("Tool2",state=NORMAL)

    button0_0["state"] = NORMAL
    button0_1["state"] = NORMAL
    button1_0["state"] = NORMAL
    button1_1["state"] = NORMAL
    button2_0["state"] = NORMAL
    button2_1["state"] = NORMAL
    button3_0["state"] = NORMAL
    button3_1["state"] = NORMAL
    button4_0["state"] = NORMAL
    button5_1["state"] = NORMAL
    
def func_save() :
    global window,canvas, paper, photo, photo2, oriX, oriY

    if photo2 == None :
        return
    saveFp = asksaveasfile(parent=window, mode="w", defaultextension=".jpg", filetypes=(("JPG 파일", "*.jpg;*.jpeg"),  ("모든 파일", "*.*") ))
    savePhoto = photo2.convert("jpg")
    savePhoto.save(filename=saveFp.name)

def func_exit() :
    window.quit()
    window.destroy()


def func_reset():
    global window,canvas, paper, photo, photo2, oriX, oriY, newX, newY
    if photo2 == None :
        return
    photo2 = photo.clone()
    newX = photo2.width 
    newY = photo2.height
    displayImage(photo2, newX, newY)
    
def func_zoomin() :
    global window,canvas, paper, photo, photo2, oriX, oriY
    scale = askinteger("확대배수", "확대할 배수를 입력하세요", minvalue=2, maxvalue=4)
    photo2 = photo.clone()
    photo2.resize( int(oriX * scale) , int(oriY * scale))
    newX = photo2.width 
    newY = photo2.height    
    displayImage(photo2, newX, newY)

def func_zoomout() :
    global window,canvas, paper, photo, photo2, oriX, oriY
    scale = askinteger("축소", "축소할 배수를 입력하세요", minvalue=2, maxvalue=4)
    photo2 = photo.clone()
    photo2.resize( int(oriX / scale) , int(oriY / scale) )
    newX = photo2.width 
    newY = photo2.height    
    displayImage(photo2, newX, newY)

def func_mirror1() :
    global window,canvas, paper, photo, photo2, oriX, oriY
    if photo2==None:        
        return
    photo2.flip()
    newX = photo2.width 
    newY = photo2.height
    displayImage(photo2, newX, newY)

def func_mirror2() :
    global window,canvas, paper, photo, photo2, oriX, oriY
    if photo2==None:        
        return
    photo2.flop()
    newX = photo2.width 
    newY = photo2.height
    displayImage(photo2, newX, newY)

def func_rotate() :
    global window,canvas, paper, photo, photo2, oriX, oriY
    degree = askinteger("회전", "회전할 각도를 입력하세요", minvalue=0, maxvalue=360)
    if photo2==None:        
        return
    if canvas != None :
        canvas.destroy()
    photo2.rotate(degree)
    newX = photo2.width 
    newY = photo2.height
    displayImage(photo2, newX, newY)

def func_bright() :
    global window,canvas, paper, photo, photo2, oriX, oriY
    value = askinteger("밝게", "값을 입력하세요(100~200)", minvalue=100, maxvalue=200)
    if photo2==None:        
        return
    photo2.modulate(value, 100, 100)
    newX = photo2.width 
    newY = photo2.height
    displayImage(photo2, newX, newY)    

def func_dark() :
    global window,canvas, paper, photo, photo2, oriX, oriY
    value = askinteger("어둡게", "값을 입력하세요(0~100)", minvalue=0, maxvalue=100)
    if photo2==None:        
        return
    photo2.modulate(value, 100, 100)
    newX = photo2.width 
    newY = photo2.height
    displayImage(photo2, newX, newY)
    
def func_clear() :
    global window,canvas, paper, photo, photo2, oriX, oriY
    value = askinteger("선명하게", "값을 입력하세요(100~200)", minvalue=100, maxvalue=200)
    if photo2==None:        
        return
    photo2.modulate(100, value, 100)
    newX = photo2.width 
    newY = photo2.height
    displayImage(photo2, newX, newY)

def func_unclear() :
    global window,canvas, paper, photo, photo2, oriX, oriY
    value = askinteger("탁하게", "값을 입력하세요(0~100)", minvalue=0, maxvalue=100)
    if photo2==None:        
        return
    photo2.modulate(100, value, 100)
    newX = photo2.width 
    newY = photo2.height
    displayImage(photo2, newX, newY)
    
def func_bw() :
    global window,canvas, paper, photo, photo2, oriX, oriY
    if photo2==None:        
        return
    photo2.type="grayscale"
    newX = photo2.width 
    newY = photo2.height
    displayImage(photo2, newX, newY)

def Destroy() :
    global window,canvas, paper, photo, photo2, oriX, oriY
    canvas.destroy()
    fileMenu.entryconfigure("열기",state=NORMAL)
    mainMenu.entryconfigure("Tool",state="disable")
    mainMenu.entryconfigure("Tool2",state="disable")
    mainMenu.entryconfigure("파일닫기",state="disable")
    button0_0["state"] = DISABLED
    button0_1["state"] = DISABLED
    button1_0["state"] = DISABLED
    button1_1["state"] = DISABLED
    button2_0["state"] = DISABLED
    button2_1["state"] = DISABLED
    button3_0["state"] = DISABLED
    button3_1["state"] = DISABLED
    button4_0["state"] = DISABLED
    button5_1["state"] = DISABLED

    
# 변수 선언 부분
window,canvas, paper=None, None, None
photo, photo2=None, None
oriX,oriY= 0,0

# 메인 코드 부분
window = Tk()
window.geometry("1280x720")
window.title("REAL Photoshop ver_1")
window.resizable(False, False)
background_img = PhotoImage(file = "PhotoShop_BackGround.png")
imagelabelbackground_img = Label(window,image = background_img)
imagelabelbackground_img.place(x= 0, y=0)


# 메뉴 생성
mainMenu = Menu(window)
window.config(menu=mainMenu)
photo = PhotoImage()


# 2.상위 메뉴 생성
fileMenu = Menu(mainMenu, tearoff=0)
mainMenu.add_cascade(label="File", menu=fileMenu)
fileMenu.add_command(label="열기", command=func_open)
fileMenu.add_command(label="저장", command=func_save)
fileMenu.add_separator()# 구분선 삽입
fileMenu.add_command(label="닫기", command=func_exit)


#차상위 메뉴
image1Menu = Menu(mainMenu, tearoff=0)
#하위메뉴
sub1Menu = Menu(image1Menu, tearoff=0)
sub1_1Menu = Menu(image1Menu, tearoff=0)
#
mainMenu.add_cascade(label="Tool", menu = image1Menu, state = "disable")
image1Menu.add_cascade(label="크기조정", menu = sub1Menu)
sub1Menu.add_command(label="확대", command=func_zoomin)
sub1Menu.add_command(label="축소", command=func_zoomout)
image1Menu.add_separator()# 구분선 삽입
image1Menu.add_cascade(label="반전", menu = sub1_1Menu)
sub1_1Menu.add_command(label="상하 반전", command=func_mirror1)
sub1_1Menu.add_command(label="좌우 반전", command=func_mirror2)
sub1_1Menu.add_command(label="회전", command=func_rotate)

#
image2Menu = Menu(mainMenu, tearoff=0)
sub2Menu = Menu(image2Menu, tearoff=0)
sub2_2Menu = Menu(image2Menu, tearoff=0)
#
mainMenu.add_cascade(label="Tool2", menu=image2Menu, state = "disable")
image2Menu.add_cascade(label="밝기조절", menu = sub2Menu)
sub2Menu.add_command(label="밝게", command=func_bright)
sub2Menu.add_command(label="어둡게", command=func_dark)
image2Menu.add_separator()# 구분선 삽입
image2Menu.add_cascade(label="선명도조절", menu = sub2_2Menu)
sub2_2Menu.add_command(label="선명하게", command=func_clear)
sub2_2Menu.add_command(label="탁하게", command=func_unclear)
image2Menu.add_separator()# 구분선 삽입
image2Menu.add_command(label="흑백", command=func_bw)


image3Menu = Menu(mainMenu, tearoff=0)
mainMenu.add_cascade(label="파일닫기", menu=image3Menu, state = "disable")
image3Menu.add_command(label="진짜로 닫니?", command=Destroy)



#버튼 그리드 생성
frame1=Frame(window, relief="solid")
#frame1.pack(side="left")
frame1.place(x=2,y=91)

#폰트 오브젝트(영어)
import tkinter.font as font
engFont = font.Font(family='Century Gothic',weight="bold", size=12)
#폰트 오브젝트(한글)
korFont = font.Font(family='배달의민족 주아', size=18)
korFont_RightBar = font.Font(family='배달의민족 주아', size=15)

button0_0 = Button(frame1, text = "확대", width=15, height=2, bg="#1B1B1B", fg="white", bd= 6, font=korFont, command=func_zoomin, state = "disable")
button0_0.grid(row = 1, column = 0)

button0_1 = Button(frame1, text = "축소", width=15, height=2, bg="#1B1B1B", fg="white", bd= 6, font=korFont, command=func_zoomout, state = "disable")
button0_1.grid(row = 2, column = 0)

button1_0 = Button(frame1, text = "밝게", width=15, height=2, bg="#1B1B1B", fg="white", bd= 6, font=korFont, command=func_bright, state = "disable")
button1_0.grid(row = 3, column = 0)

button1_1 = Button(frame1, text = "어둡게", width=15, height=2, bg="#1B1B1B", fg="white", bd= 6, font=korFont, command=func_dark, state = "disable")
button1_1.grid(row = 4, column = 0)

button2_0 = Button(frame1, text = "상하반전", width=15, height=2, bg="#1B1B1B", fg="white", bd= 6, font=korFont, command=func_mirror1, state = "disable")
button2_0.grid(row = 5, column = 0)

button2_1 = Button(frame1, text = "좌우반전", width=15, height=2, bg="#1B1B1B", fg="white", bd= 6, font=korFont, command=func_mirror2, state = "disable")
button2_1.grid(row = 6, column = 0)



frame2=Frame(window, relief="solid")
#frame2.pack(side="right")
frame2.place(x=1100,y=91)
button3_0 = Button(frame2, text = "그림 제거", width=14, height=2, bg="#262626", fg="white", bd= 1, font=korFont_RightBar, command = Destroy, state = "disable")
button3_0.grid(row = 1, column = 0)
button3_1 = Button(frame2, text = "사진 초기화", width=14, height=2, bg="#262626", fg="white", bd= 1, font=korFont_RightBar, command = func_reset, state = "disable")
button3_1.grid(row = 2, column = 0)
button4_0 = Button(frame2, text = "뭐라고적지", width=14, height=2, bg="#262626", fg="white", font=korFont_RightBar, bd= 1)
button4_0.grid(row = 3, column = 0)
button5_1 = Button(frame2, text = "뭐라고적지", width=14, height=2, bg="#262626", fg="white", font=korFont_RightBar, bd= 1)
button5_1.grid(row = 4, column = 0)
button6_0 = Button(frame2, text = "뭐라고적지", width=14, height=2, bg="#262626", fg="white", font=korFont_RightBar, bd= 1)
button6_0.grid(row = 5, column = 0)
button6_1 = Button(frame2, text = "뭐라고적지", width=14, height=2, bg="#262626", fg="white", font=korFont_RightBar, bd= 1)
button6_1.grid(row = 6, column = 0)



frame3=Frame(window, relief="solid")
frame3.place(x=2,y=24)
button7_0 = Button(frame3, text = "파일 열기", width=10, height=1, bg="#262626", fg="white", bd= 1, font=korFont_RightBar, command = func_open)
button7_0.grid(row = 0, column = 0)
button7_1 = Button(frame3, text = "파일 저장", width=10, height=1, bg="#262626", fg="white", bd= 1, font=korFont_RightBar, command = func_save)
button7_1.grid(row = 0, column = 1)


frame4=Frame(window, relief="solid")
frame4.place(x=1125,y=24)
button8_0 = Button(frame4, text = "종료", width=10, height=1, bg="#262626", fg="white", bd= 1, font=korFont_RightBar, command = func_exit)
button8_0.grid(row = 0, column = 0)




window.mainloop()
コンポーネント参照

caat.jpg

PhotoShop_BackGround.png
1280x720
font - BMJUA.ttf