在用户输入值后检查条目

时间:2016-10-13 13:33:32

标签: python python-3.x tkinter

我使用Tkinter和Python 3.4编写了一个图形界面。在我的脚本中,我使用ttk.Entry生成一个输入空间,用户可以在其中输入值。

当用户完成小费时,是否可以执行操作,例如叫一个功能?如果不可能,我会使用按钮。

以下是代码的摘录:

ttk.Label(mainframe, text="Enter your data path", font=('Times', '14', 'bold italic')).grid(column=1, row=2, sticky=E)

path_frame = StringVar()
input_path_frame = ttk.Entry(mainframe, width=100, textvariable=path_frame)
input_path_frame.grid(column=2, row=2, columnspan=2, sticky=(N))

我希望在' input_path_frame'满满的。

感谢您的时间

1 个答案:

答案 0 :(得分:1)

您可以添加FocusOut事件管理器功能。一旦用户完成在字段中的输入并移动到其他地方,该事件管理器就会执行:

input_path_frame.bind( '<FocusOut>',
    lambda e, strvar=path_frame: check_field(e, strvar)
  )
# check_field function would be executed as soon as the focus leaves the field

check_field函数用于检查input_path_frame字段是否为空。

它会是这样的:

def check_field(e, strvar):
  # do stuff
  # check if empty
  # run tests etc
  return strvar.get()

如果您想同时获取结果键,可以嵌套两个事件管理功能,如<FocusIn><Key>。并且可以<key> <FocusOut>取消绑定input_path_frame.bind("<FocusIn>", lambda e: key_bind_func) input_path_frame.bind("<FocusOut>", lambda e: key_unbind_func)

androidNDKRoot = /path/to/ndk-R13-standalone ;

using clang : android
:
$(androidNDKRoot)/bin/arm-linux-androideabi-clang++
:
;
相关问题