A Comprehensive Introduction to Python Programming and ... - MSDL
A Comprehensive Introduction to Python Programming and ... - MSDL
A Comprehensive Introduction to Python Programming and ... - MSDL
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
3.2 The Different Widgets 33 / 75<br />
3.2.13 Scrollbar<br />
The Scrollbar widget is a typical scrollbar, with arrows at both ends <strong>and</strong> a slider portion<br />
in the middle. Unlike typical scrollbars, its color can be modified.<br />
The Scrollbar widget provides the following options:<br />
Option Description<br />
comm<strong>and</strong> Used <strong>to</strong> update the associated widget. This is typically<br />
the xview or yview method of the scrolled widget.<br />
If the user drags the scrollbar slider, the comm<strong>and</strong> is<br />
called as callback(MOVETO, offset) where offset 0.0<br />
means that the slider is in its <strong>to</strong>pmost (or leftmost) position,<br />
<strong>and</strong> offset 1.0 means that it is in its bot<strong>to</strong>mmost<br />
(or rightmost) position. If the user clicks the arrow but<strong>to</strong>ns,<br />
or clicks in the trough, the comm<strong>and</strong> is called as<br />
callback(SCROLL, step, what). The second argument<br />
is either ”-1” or ”1” depending on the direction, <strong>and</strong><br />
the third argument is UNITS <strong>to</strong> scroll lines (or other<br />
units relevant for the scrolled widget), or PAGES <strong>to</strong><br />
scroll full pages.<br />
orient Defines how <strong>to</strong> draw the scrollbar. Use one of HORI-<br />
ZONTAL or VERTICAL. Default is VERTICAL.<br />
The Scrollbar widget defines the following methods:<br />
3.2.14 Text<br />
3.2.15 Canvas<br />
Method Description<br />
The canvas widget provides the basic graphics facilities for Tkinter, <strong>and</strong> so more advanced<br />
functions. Drawing on the canvas is done by creating various items on it. It is<br />
important <strong>to</strong> note at this stage that items are not widgets, even though they are similar<br />
in many ways. Each item on a canvas is enclosed by a bounding box, which is defined<br />
using 2 points: the <strong>to</strong>p-left corner <strong>and</strong> the bot<strong>to</strong>m-right corner of the box. Tkinter uses<br />
two coordinate systems simultaneously: the canvas coordinate system <strong>and</strong> the window<br />
coordinate system. Both systems express positions relative <strong>to</strong> the <strong>to</strong>p-left corner, with<br />
X-coordinates increasing <strong>to</strong> the right <strong>and</strong> Y-coordinates increasing downwards. However,<br />
the origin for the two systems is different. The window system expresses the<br />
coordinates by placing the origin at the <strong>to</strong>p-left corner of the visible portion of the canvas,<br />
while the canvas system places its origin at the <strong>to</strong>p-corner of the canvas widget,<br />
even it is not visible. The difference is important when h<strong>and</strong>ling mouse events bound<br />
<strong>to</strong> the canvas since the event object receives its coordinates in the window system.<br />
Luckily, the canvas widget provides the necessary methods <strong>to</strong> convert coordinates <strong>to</strong><br />
the canvas system, through calls <strong>to</strong> the canvasx( ) <strong>and</strong> canvasy( ) methods.<br />
The Tkinter canvas supports the following st<strong>and</strong>ard items (more can also be added):