#Pmw copyright
#Copyright 1997-1999 Telstra Corporation Limited, Australia #Copyright 2000-2002 Really Good Software Pty Ltd, Australia
#Permission is hereby granted, free of charge, to any person obtaining a copy #of this software and associated documentation files (the "Software"), to deal #in the Software without restriction, including without limitation the rights #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #copies of the Software, and to permit persons to whom the Software is furnished #to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all #copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, #INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A #PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION #OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE #SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from Tkinter import * import Pmw
eventList = { '2': 'KeyPress', '3': 'KeyRelease', '4': 'ButtonPress', '5': 'ButtonRelease', '6': 'Motion', '7': 'Enter', '8': 'Leave', '9': 'FocusIn', '10': 'FocusOut', '12': 'Expose', '15': 'Visibility', '17': 'Destroy', '18': 'Unmap', '19': 'Map', '21': 'Reparent', '22': 'Configure', '24': 'Gravity', '26': 'Circulate', '28': 'Property', '32': 'Colormap','36': 'Activate', '37': 'Deactivate' }
root = Tk()
def reportEvent(event): rpt = 'nn%s' % (80*'=') rpt = '%snEvent: type=%s (%s)' % (rpt, event.type, eventList.get(event.type, 'Unknown')) rpt = '%sntime=%s' % (rpt, event.time) rpt = '%s widget=%s' % (rpt, event.widget) rpt = '%s x=%d, y=%d'% (rpt, event.x, event.y) rpt = '%s x_root=%d, y_root=%d' % (rpt, event.x_root, event.y_root) rpt = '%s y_root=%d' % (rpt, event.y_root) rpt = '%snserial=%s' % (rpt, event.serial) rpt = '%s num=%s' % (rpt, event.num) rpt = '%s height=%s' % (rpt, event.height) rpt = '%s width=%s' % (rpt, event.width) rpt = '%s keysym=%s' % (rpt, event.keysym) rpt = '%s ksNum=%s' % (rpt, event.keysym_num)
#### some event types don't have these attributes try: rpt = '%s focus=%s' % (rpt, event.focus) except: pass try: rpt = '%s send=%s' % (rpt, event.send_event) except: pass text2.yview(END) text2.insert(END, rpt) frame = Frame(root, takefocus=1, highlightthickness=2) text = Entry(frame, width=100, takefocus=1) text2 = Pmw.ScrolledText(frame)
for event in eventList.values(): frame.bind('<%s>' % event, reportEvent) text.bind('<%s>' % event, reportEvent)
text.pack() text2.pack(fill=BOTH, expand=YES) frame.pack() text.focus_set() root.mainloop()
|