Python 如何在Tkinter中修复此Textwidget?

Python 如何在Tkinter中修复此Textwidget?,python,tkinter,Python,Tkinter,如果在文本字段中键入2,为什么y不输出两次? 谢谢你的帮助 from tkinter import * root = Tk() root.geometry("500x450") def copy(): y = txt.get(1.0, END) print(y) if y == "2": print("Check") txt = Text(root, width=60, height=20,

如果在文本字段中键入2,为什么y不输出两次? 谢谢你的帮助

from tkinter import *

root = Tk()
root.geometry("500x450")

def copy():
    y = txt.get(1.0, END)
    print(y)
    if y == "2":
        print("Check")

txt = Text(root, width=60, height=20, font=("Arial", 12))
txt.place(x=0, y=0)

btn = Button(root, text="Copy", command=copy)
btn.place(x=250, y=400)

mainloop()

因为这里有一个隐藏的
\n
。如果您将If更改为
If y==“2\n”:
它将打印check

,因为这里有一个隐藏的
\n
。如果将If更改为
If y==“2\n”:
它将打印检查

为什么不使用
条目
而不是
文本
?为什么不使用
条目
而不是
文本