Thread: Tkinter events

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    12

    Tkinter events


    I was just trying to figure out what all the events in Tkinter do....its a simple program...just printing each line when the evnt occurs...but my program *does nothing* for any key movements...I've tried using the <Key> event too ...but to disappointment! Whats the prob here...the mouse events are working fine...

    PHP Code:
    from Tkinter import *
    import tkMessageBox
    root
    =Tk()
    def singleClick(event):
        print 
    "That was a single click at"event.xevent.y

    def doubleClick
    (event):
        print 
    "That was a double click at"event.xevent.y

    def entry
    (event):
        print 
    "The mouse pointer *entered* the widget!"

    def exit(event):
        print 
    "The mouse pointer *left* the widget!"

    def enter(event):
        print 
    "The user just pressed the Enter key"
        


    def callback():
        if 
    tkMessageBox.askokcancel("QUIT","Do you really wish to quit?"):
            
    root.destroy()
        
    frame=Frame(root,width=300,height=300)

    frame.bind("<Double-Button-1>",doubleClick)
    frame.bind("<Button-1>",singleClick)
    frame.bind("<Enter>",entry)
    frame.bind("<Leave>",exit)
    frame.bind("<Return>",enter)
    frame.pack()
    root.protocol("WM_DELETE_WINDOW",callback)
    root.mainloop() 

    Thanks,
    Subha
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Try this :
    Code:
    textTest=Text(root,width=80,height=10)
    
    textTest.bind("<Double-Button-1>",doubleClick)
    textTest.bind("<Button-1>",singleClick)
    textTest.bind("<Enter>",entry)
    textTest.bind("<Leave>",exit)
    textTest.bind("<Return>",enter)
    textTest.pack()
    It looks like Tkinter does not consider key events to be relevant to simple widgets like Frame. Key events work fine for Menus, Entry and Text.

    grim
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    12
    Thanks Grim. I got it using the Text.

    Subha

IMN logo majestic logo threadwatch logo seochat tools logo