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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

If you want to change the text label on a radiobutton during the execution of yourapplication, set its textvariable option to a StringVar. Then your program canchange the text label by passing the new label text to the variable’s .set() method. Scale: For a scale widget, set its variable option to a control variable of any class,and set its from_ and to options to the limiting values <strong>for</strong> the opposite ends ofthe scale. For example, you could use an IntVar and set the scale’s from_=0 andto=100. Then every user change to the widget would change the variable’s value tosome value between 0 and 100 inclusive. Your program can also move the slider byusing the .set() method on the control variable. To continue the above example,.set(75) would move the slider to a position three-fourths of the way along itstrough.To set up a Scale widget <strong>for</strong> floating values, use a DoubleVar.You can use a StringVar as the control variable of a Scale widget. You will stillneed to provide numeric from_ and to values, but the numeric value of the widgetwill be converted to a string <strong>for</strong> storage in the StringVar. Use the scale’s digitsoption to control the precision of this conversion.21. Focus: routing keyboard inputTo say a widget has focus means that keyboard input is currently directed to that widget. By focus traversal, we mean the sequence of widgets that will be visited as the usermoves from widget to widget with the TAB key. See below <strong>for</strong> the rules <strong>for</strong> thissequence. You can traverse backwards using SHIFT-TAB. The Entry and Text widgets are intended to accept keyboard input, and if an entryor text widget currently has the focus, any characters you type into it will be addedto its text. Because Text widgets can contain tab characters, you must use the special keysequence CONTROL-TAB to move the focus past a text widget. Most of the other types of widgets will normally be visited by focus traversal, andwhen they have focus: Button widgets can be “pressed” by pressing the spacebar. Checkbutton widgets can be toggled using the spacebar. In Listbox widgets, the up- and down-arrows scroll up or down one line;the PAGEUP and PAGEDOWN keys scroll by pages; and the spacebar selects thecurrent line, or de-selects it if it was already selected. You can set a Radiobutton widget by pressing the spacebar. Horizontal Scale widgets respond to the left- and right-arrow keys, and verticalones respond to the up- and down-arrow. In a Scrollbar widget, the PAGEUP and PAGEDOWN keys move the scrollbarby pageloads. The up- and down-arrows will move vertical scrollbars by units,and the left- and right-arrow keys will move horizontal scrollbars by units.New Mexico Tech Computer Center <strong>Tkinter</strong> <strong>reference</strong>: Focus Page 75

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

Saved successfully!

Ooh no, something went wrong!