Python

[Python] tkinter 사용 예제 - 슬래쉬, 역슬래쉬 변경 GUI

1984 2022. 9. 2. 20:26

실행화면

import tkinter

def Convert():
    text = textExample.get("1.0","end")
    if '/' in text:
        text = text.replace('/', '\\')
    elif '\\' in text :
        text = text.replace('\\', '/')
    else :
        print('변경할 문자가 없습니다.')
    textExample.delete(1.0,"end")
    textExample.insert(1.0, text)

# 화면 생성
window = tkinter.Tk()
# 제목
window.title("Convert Slash")
# 화면 크기 설정
window.geometry('320x240')
# label
label = tkinter.Label(window, text="입력란", font=("돋음", 10))
# textbox
textExample=tkinter.Text(window, height=10)
textExample.pack()
# 버튼
btnRead=tkinter.Button(window, height=1, width=10, text="Convert", command=Convert)
btnRead.pack()
# 프로그램이 종료될 때까지 실행됨
window.mainloop()
728x90