[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1
Got left mouse button drag: Widget=.25763696 X=145 Y=50
Got left mouse button drag: Widget=.25763696 X=146 Y=51
Got left mouse button drag: Widget=.25763696 X=149 Y=53
Got key press: s
Got key press: p
Got key press: a
Got key press: m
Got key press: 1
Got key press: -
Got key press: 2
Got key press:.
Got return key press
Got up arrow key press
Got left mouse button click: Widget=.25763696 X=300 Y=68
Got double left mouse click Widget=.25763696 X=300 Y=68

For mouse-related events, callbacks print the X and Y coordinates of the mouse pointer,
in the event object passed in. Coordinates are usually measured in pixels from the
upper-left corner (0,0), but are relative to the widget being clicked. Here’s what is
printed for a left, middle, and double-left click. Notice that the middle-click callback
dumps the entire argument—all of the Event object’s attributes (less internal names
that begin with “” which includes the doc__ string, and default operator overload-
ing methods inherited from the implied object superclass in Python 3.X). Different
event types set different event attributes; most key presses put something in char, for
instance:


C:\...\PP4E\Gui\Tour> python bind.py
Got left mouse button click: Widget=.25632624 X=6 Y=6
Got middle mouse button click: Widget=.25632624 X=212 Y=95
<tkinter.Event object at 0x018CA210>
char => ??
delta => 0
height => ??
keycode => ??
keysym => ??
keysym_num => ??
num => 2
send_event => False
serial => 17
state => 0
time => 549707945
type => 4
widget => .25632624
width => ??
x => 212
x_root => 311
y => 95
y_root => 221
Got left mouse button click: Widget=.25632624 X=400 Y=183
Got double left mouse click Widget=.25632624 X=400 Y=183

446 | Chapter 8: A tkinter Tour, Part 1

Free download pdf