Python Tkinter Canvas fail to bind keyboard

前端 未结 3 1989
刺人心
刺人心 2020-12-04 01:22

I\'ve been running a small script like this

from Tkinter import *
root = Tk()
def callback(event):
    print \"callback\"
w = Canvas(root, width=300, height         


        
3条回答
  •  广开言路
    2020-12-04 02:15

    To avoid the "clicking on the canvas to activate the key bindings", I found simpler code at the following site:

    http://ubuntuforums.org/showthread.php?t=1378609

    He is attempting to bind a frame, but I implemented it in my own code and the canvas widget works as well. Your code will look like the following:

    w.focus_set()
    w.bind(, callback)
    

提交回复
热议问题