我正在使用 Tkinter 为我正在创建的简单几何计算器创建 GUI。
基本上,我拥有的是一个输入框。我想要的是程序/GUI/系统检测程序用户何时在输入框中点击“Enter”或“return”键。当检测到这一点时,我希望将条目框的内容附加到我之前定义的列表中。我还希望在显示列表内容(包括附加项)的 GUI 上创建一个简单的标签。请注意,该列表以任何内容开头。
到目前为止,这是我的代码:
from tkinter import *
#Window setup(ignore this)
app = Tk()
app.title('Geometry Calculator')
app.geometry('384x192+491+216')
app.iconbitmap('Geo.ico')
app.minsize(width=256, height=96)
app.maxsize(width=384, height=192)
app.configure(bg='WhiteSmoke')
#This is the emtry list...
PointList = []
#Here is where I define the variable that I will be appending to the list (which is the object of the Entry box below)
StrPoint = StringVar()
def list_add(event):
#I don't really know how the bind-checking works and how I would implement it; I want to check if the user hits enter while in the Entry box here
if event.char == '':
PointList.append(StrPoint)
e1 = Entry(textvariable=StrPoint).grid(row=0, column=0)
app.bind('<Return>', list_add)
mainloop()
我真的不知道检查“返回”然后在 if 语句中使用它的正确方法。我希望您能理解我想要寻求帮助的内容,并且我已经四处寻找我可以理解但没有成功的解释。