TkInter keypress, keyrelease events

后端 未结 4 1816
野性不改
野性不改 2020-12-01 11:52

I understood that the Tk keypress and keyrelease events were supposed only to fire when the key was actually pressed or released?

However with the following simple c

4条回答
  •  离开以前
    2020-12-01 12:35

    how about;

    from Tkinter import *
    
    wn = Tk()
    wn.title('KeyDetect')
    
    m = 0
    
    def down(e):
        if m == 0:
            print 'Down\n', e.char, '\n', e
            global m
            m = 1
    
    def up(e):
        if m == 1:
            print 'Up\n', e.char, '\n', e
            global m
            m = 0
    
    wn.bind('', down)
    wn.bind('', up)
    
    wn.mainloop()
    

    now it won't repeat.

提交回复
热议问题