Tkinter -- 事件与绑定

参考官网上示例,链接effbot.ort/tkinterbook 


from Tkinter import *
import tkMessageBox



root = Tk()

def btnClick(ev):
    frame.focus_set()  # must  other  is not work
    print "left buttn clicked at ",ev.x,ev.y

def key(ev):

    print "you are input ",repr(ev.char)

def closeWindow():
    if tkMessageBox.askokcancel("Quit","Do you want to quit?"):
        root.destroy()

frame = Frame(root,width=100,height=100)

frame.bind('',btnClick)  # left button 1   right button 2
frame.bind('',key)

frame.pack()

root.protocol('WM_DELETE_WINDOW',closeWindow)
root.mainloop()


你可能感兴趣的:(Tkinter)