12.07.2015 Views

Tkinter reference: A GUI for Python

Tkinter reference: A GUI for Python

Tkinter reference: A GUI for Python

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

22.2 Event sequences<strong>Tkinter</strong> has a powerful and general method <strong>for</strong> allowing you to define exactly whichevents, both specific and general, you want to bind to handlers.In general, an event sequence is a string containing one or more event patterns. Each eventpattern describes one thing that can happen. If there is more than one event pattern ina sequence, the handler will be called only when all the patterns happen in that samesequence.The general <strong>for</strong>m of an event pattern is: The entire pattern is enclosed inside . The type describes the general kind of event, such as a key press or mouse click. You can add optional modifier items be<strong>for</strong>e the type to specify combinations suchas the SHIFT or CONTROL keys being depressed during other key presses or mouseclicks. You can add optional detail items to describe what key or mouse button you’relooking <strong>for</strong>. For mouse buttons, this is 1 <strong>for</strong> button 1, 2 <strong>for</strong> button 2, or 3 <strong>for</strong> button3. The usual setup has button 1 on the left and button 3 on the right, but lefthanderscan swap these positions. For keys on the keyboard, this is either the key’s character (<strong>for</strong> single-characterkeys like the A or * key) or the key’s name; see below <strong>for</strong> a list of all key names.Here are some examples to give you the flavor of event patterns:22.3 Event types: The user pressed the first mouse button.: The user pressed the H key.: The user pressed CONTROL-SHIFT-H.The full set of event types is rather large, but a lot of them are not commonly used. Hereare most of the ones you’ll need:ActivateButtonButtonReleaseConfigureDeactivateDestroyA widget is changing from being inactive to beingactive. This refers to changes in the state optionof a widget such as a button changing from inactive(grayed out) to active.The user pressed one of the mouse buttons. Thedetail part specifies which button.The user let up on a mouse button.The user changed the size of a widget, <strong>for</strong> exampleby dragging a corner or side of the window.A widget is changing from being active to beinginactive. This refers to changes in the state optionof a widget such as a radiobutton changing fromactive to inactive (grayed out).A widget is being destroyed.New Mexico Tech Computer Center <strong>Tkinter</strong> <strong>reference</strong>: Events Page 78

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!