Tkinter 텍스트 위젯을 사용하여 텍스트를 삽입하고 정보를 표시하며 텍스트 위젯에서 출력을 얻을 수 있습니다. 텍스트 위젯에서 사용자 입력을 얻으려면 get()을 사용해야 합니다. 방법. 작동 방식을 보기 위해 예를 들어 보겠습니다.
예시
# Import the required library
from tkinter import *
from tkinter import ttk
# Create an instance of tkinter frame
win=Tk()
# Set the geometry
win.geometry("700x350")
def get_input():
label.config(text=""+text.get(1.0, "end-1c"))
# Add a text widget
text=Text(win, width=80, height=15)
text.insert(END, "")
text.pack()
# Create a button to get the text input
b=ttk.Button(win, text="Print", command=get_input)
b.pack()
# Create a Label widget
label=Label(win, text="", font=('Calibri 15'))
label.pack()
win.mainloop() 출력
위의 코드를 실행하면 텍스트 위젯이 포함된 창이 표시됩니다. 텍스트 위젯에 내용을 입력하고 "인쇄"를 클릭합니다. 버튼을 눌러 출력을 표시합니다.
