赞
踩
from tkinter import * def printcoords(event): print(event.x, event.y) root = Tk() bt1 = Button(root, text='leftmost button') bt1.bind('<Button-1>', printcoords) bt2 = Button(root, text='middle button') bt2.bind('<Button-2>', printcoords) bt3 = Button(root, text='rightmost button') bt3.bind('<Button-3>', printcoords) bt4 = Button(root, text='double click') bt4.bind('<Button-4>', printcoords) bt5 = Button(root, text='triple click') bt5.bind('<Button-5>', printcoords) bt1.pack() bt2.pack() bt3.pack() bt4.pack() bt5.pack() root.mainloop()
from tkinter import * def printcoords(event): print(event.x, event.y) root = Tk() bt1 = Button(root, text='leftmost button') bt1.bind('<B1-Motion>', printcoords) bt2 = Button(root, text='middle button') bt2.bind('<B2-Motion>', printcoords) bt3 = Button(root, text='rightmost button') bt3.bind('<B3-Motion>', printcoords) bt1.pack() bt2.pack() bt3.pack() root.mainloop()
from tkinter import * def printcoords(event): print(event.x, event.y) root = Tk() bt1 = Button(root, text='leftmost button') bt1.bind('<ButtonRelease-1>', printcoords) bt2 = Button(root, text='middle button') bt2.bind('<ButtonRelease-2>', printcoords) bt3 = Button(root, text='rightmost button') bt3.bind('<ButtonRelease-3>', printcoords) bt1.pack() bt2.pack() bt3.pack() root.mainloop()
from tkinter import *
def printcoords(event):
print(event.x, event.y)
root = Tk()
bt1 = Button(root, text='leftmost button')
bt1.bind('<Enter>', printcoords)
bt1.pack()
root.mainloop()
from tkinter import *
def printcoords(event):
print(event.x, event.y)
root = Tk()
bt1 = Button(root, text='leftmost button')
bt1.bind('<Leave>', printcoords)
bt1.pack()
root.mainloop()
from tkinter import * def printcoords(event): print('event.char =', event.char) print('event.keycode=', event.keycode) root = Tk() 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) bt1.pack() bt2.pack() bt3.pack() root.mainloop()
from tkinter import * def printcoords(event): print('event.char =', event.char) print('event.keycode=', event.keycode) root = Tk() bt1 = Button(root, text='press backspace') bt1.bind('<Key>', printcoords) bt1.pack() root.mainloop()
from tkinter import * def printcoords(event): print('event.char =', event.char) print('event.keycode=', event.keycode) root = Tk() bt1 = Button(root, text='press shift-up') bt1.bind('<Shift-Up>', printcoords) bt2 = Button(root, text='press Control-Alt-a') bt2.bind('<Control-Alt-a>', printcoords) bt1.pack() bt2.pack() root.mainloop()
from tkinter import *
def printsize(event):
print(event.width, event.height)
root = Tk()
root.bind('<Configure>', printsize)
root.mainloop()
from tkinter import * def printevent(event): print('<Key>', event.keycode) def printreturn(event): print('<Return', event.keycode) root = Tk() root.bind('<Key>', printevent) root.bind('<Return>', printreturn) root.mainloop()
from tkinter import *
def printevent(event):
print('<Key>', event.keycode)
root = Tk()
bt1 = Button(root, text='instance event')
bt1.bind('<Key>', printevent)
bt1.focus_set()
bt1.pack()
root.mainloop()
from tkinter import * def printevent(event): print('<Key>', event.keycode) def printToplevel(event): print('<toplevel>', event.keycode) def printClass(event): print('<bind_class>', event.keycode) def printAppAll(event): print('<bind_all>', event.keycode) root = Tk() bt1 = Button(root, text='instance event') bt1.bind('<Key>', printevent) bt1.winfo_toplevel().bind('<Return>', printToplevel) root.bind_class('Button', '<Return>', printClass) bt1.bind_all('<Return>', printAppAll) bt1.focus_set() bt1.pack() root.mainloop()
from tkinter import * def printClass(event): print('<bind_class>', event.keycode) root = Tk() root.bind_class('Button', '<Return>', printClass) bt1 = Button(root, text='a button') bt2 = Button(root, text='another button') bt1.focus_set() bt1.pack() bt2.pack() root.mainloop()
from tkinter import *
def printprotocol():
print('WM_DELETE_WINDOW')
root.destroy()
root = Tk()
root.protocol('WM_DELETE_WINDOW', printprotocol)
root.mainloop()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。