- ''
- ''
-
-
- from tkinter import *
-
- root = Tk()
-
-
- def printCoords(event):
- print(event.x, event.y)
-
-
-
- bt1 = Button(root, text='leftmost button')
- bt1.bind('<Leave>', printCoords)
-
- bt1.grid()
-
- root.mainloop()
-
- ''
-
-
- from tkinter import *
-
- root = Tk()
-
-
- def printCoords(event):
- print('event.char = ', event.char)
- print('event.keycode = ', event.keycode)
-
-
-
- bt1 = Button(root, text='Press BackSpace')
- bt1.bind('<BackSpace>', printCoords)
-
-
- bt2 = Button(root, text='Press Enter')
- bt2.bind('<Return>', printCoords)
-
-
- bt3 = Button(root, text='F5')
- bt3.bind('<F5>', printCoords)
-
-
- bt4 = Button(root, text='Left Shift')
- bt4.bind('<Shift_L>', printCoords)
-
-
- bt5 = Button(root, text='Right Shift')
- bt5.bind('<Shift_R>', printCoords)
-
-
- bt1.focus_set()
- bt1.grid()
- bt2.grid()
- bt3.grid()
- bt4.grid()
- bt5.grid()
-
- root.mainloop()
-
-
-
-
-
- ''
-
-
- from tkinter import *
-
- root = Tk()
-
-
- def printCoords(event):
- print('event.char = ', event.char)
- print('event.keycode = ', event.keycode)
-
-
-
- bt1 = Button(root, text='Press BackSpace')
- bt1.bind('<Key>', printCoords)
-
-
- bt1.focus_set()
- bt1.grid()
-
- root.mainloop()
-
-
- ''
-
-
- from tkinter import *
-
- root = Tk()
-
-
- def printCoords(event):
- print('event.char = ', event.char)
- print('event.keycode = ', event.keycode)
-
-
-
- bt1 = Button(root, text='Press "a" ')
- bt1.bind('a', printCoords)
-
-
- bt2 = Button(root, text='Press spacebar')
- bt2.bind('<space>', printCoords)
-
-
- bt3 = Button(root, text='less than key')
- bt3.bind('<less>', printCoords)
-
-
- bt1.focus_set()
-
- bt1.grid()
- bt2.grid()
- bt3.grid()
-
- root.mainloop()
-
-
- ''
-
-
- from tkinter import *
-
- root = Tk()
-
-
- def printCoords(event):
- print('event.char = ', event.char)
- print('event.keycode = ', event.keycode)
-
-
-
- bt1 = Button(root, text='Press Shift - Up')
- bt1.bind('<Shift-Up>', printCoords)
-
-
- bt2 = Button(root, text='Control-Alt-b')
- bt2.bind('<Control-Alt-b>', printCoords)
-
-
-
-
-
-
-
-
- bt1.focus_set()
- bt1.grid()
- bt2.grid()
-
- root.mainloop()
-
- ''
-
-
- from tkinter import *
-
- root = Tk()
-
-
- def printSize(event):
- print((event.width, event.height))
-
-
- root.bind('<Configure>', printSize)
-
- root.mainloop()
-
转自:http://blog.csdn.net/aa1049372051/article/details/51889900