当我在条目中输入一个值时,它应该打印到控制台,但是,它会打印一个新行,而不打印其他任何内容。我是tkinter的新手,目前正在测试。
def main(self, event= None):
v = StringVar()
entry1 = Entry(width = 20, textvariable = v)
entry1.bind("<Return>", self.main)
entry1.focus()
self.removeWidgits()
homeLabel.place_forget()
exitButton.pack(side = BOTTOM)
entry1.place(x = 0, y = 0)
v = entry1.get()
print(v)
答案 0 :(得分:0)
从您的代码看来,您想在按下Return
时在条目中打印文本。这是您的代码的副本,可按Enter键打印文本。
from tkinter import *
root = Tk()
v = StringVar()
entry1 = Entry(width = 20, textvariable = v)
entry1.bind("<Return>", lambda _:print(entry1.get()))
entry1.focus()
entry1.place(x = 0, y = 0)
root.mainloop()