0
你好我有問題綁定w + d在我的代碼。我看到如何用Ctrl + /和類似的東西來做到這一點,但使用兩個字母是不同的?我試圖用一些不同的方式來做到這一點,這裏是我使用的路線。蟒蛇Tkinter綁定2.7.9 w-d
root.bind('w-d',lambda x: upleftc())
你好我有問題綁定w + d在我的代碼。我看到如何用Ctrl + /和類似的東西來做到這一點,但使用兩個字母是不同的?我試圖用一些不同的方式來做到這一點,這裏是我使用的路線。蟒蛇Tkinter綁定2.7.9 w-d
root.bind('w-d',lambda x: upleftc())
這是一個有點不清楚,你要完成什麼,但如果你想綁定到字母「W」後面的字母「d」的組合,你會綁定到兩個 - 事件序列"<w><d>"
,或更簡單地,"wd"
。
有關如何指定事件的權威性文檔,請參見部分"Event Patterns" in the official tcl/tk documentation。
下面是一個例子:
import Tkinter as tk
class Example(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.entry = tk.Entry(self)
self.entry.pack(fill="x")
self.entry.bind("<w><d>", self.onWD)
# alternatively: self.entry.bind("wd", self.onWD)
def onWD(self, event):
print "boom!"
if __name__ == "__main__":
root = tk.Tk()
Example(root).pack(fill="both", expand=True)
root.mainloop()
你的標題和代碼秀 「W-d」,該問題的文本顯示 「W + d」。你是否試圖綁定字母「w」和字母「d」的雙鍵組合? –
我試圖讓它到如果兩者都立即按下綁定將去def upleftc,如果他們保持這種方式,它將繼續運行該代碼。 – user3723323