【问题标题】:How can i fix this Textwidget in Tkinter?如何在 Tkinter 中修复这个 Textwidget?
【发布时间】:2020-11-13 03:24:09
【问题描述】:

如果在文本字段中输入 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()

【问题讨论】:

  • 为什么不用Entry 而不是Text

标签: python tkinter


【解决方案1】:

因为这里有一个隐藏的\n。如果您将 if 更改为 if y == "2\n":,它将打印支票

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-07
    • 1970-01-01
    • 2017-11-17
    • 2020-08-24
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    相关资源
    最近更新 更多