파이썬

파이썬 텍스트 입력 창 사용하기

blacknabis 2023. 5. 14. 00:31
import tkinter

#함수와 연동 하기 위한 전역변수
global Msg
global window

window = tkinter.Tk()

#확인 버튼 함수
def confirm():
    global Msg
    global window
    Msg = input_text.get()
    
    #윈도우를 종료한다.
    window.quit()

window.title("Input Text")    
input_text = tkinter.Entry(window, width=30)
input_text.grid(column=0, row=2)

button = tkinter.Button(window, text="확인", command=confirm)
button.grid(column=1, row=2)

window.mainloop()

#입력받은 메세지 출력
print(Msg)

 

메시지 박스 창
결과 출력