![](/img/trans.png)
[英]How to make Tkinter run in the background or make it handle keypress events outside of the Tkinter window?
[英]How to run a method on keypress in tkinter
我有一個輸入字段,當我在數據字段中輸入時,我需要一個方法來更新要運行的樹視圖小部件。 目前,我可以輸入搜索參數,然后按“搜索”按鈕,它將運行搜索樹視圖以查找指定客戶端的方法,但我希望樹視圖在輸入條目時更新,而不是通過按下按鈕
我不確定這是否可行,是否應該通過綁定鍵來實現,或者是否有辦法使用事件循環來實現這一點?
請參閱此 SO 帖子: TkInter keypress, keyrelease events
本質上:
from Tkinter import *
def keyup(e):
pass;
# e.char contains the pressed key if you need that info
# use your search function here
編輯(抱歉我忘了這個):
您需要使用以下內容將 keyup 函數綁定到您的小部件:
frame.bind("<KeyRelease>", keyup) # you can also bind to a search widget
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.