Wiki - Week Three - An Introduction To Interactive Programming in Python
Wiki - Week Three - An Introduction To Interactive Programming in Python
Week three
Canvas Canvas and drawing The canvas is the area associated with an application where information contain in the application may be drawn. In SimpleGUI applications, the width and height of the canvas are specified (in pixels) in c r e a t e _ f r a m e. (A pixel is the smallest unit of area that your computer can draw in.) The origin for the canvas is the upper left-hand corner. Positions in the canvas are specified as pairs [ x , y ] where x is the horizontal coordinate and
y is the vertical coordinate.
Lecture examples - Canvas and Drawing More examples - Structure Event-driven drawing Canvas and drawing Computers refresh their screens around 60 times per sec. For each application, the computer calls a special event handler, the draw handler, that is registered to the application. In SimpleGUI, the draw handler is registered via s e t _ d r a w _ h a n d l e r. The draw handler can modify the canvas via simple draw operations defined in SimplGUI Lecture examples - Canvas and Drawing More examples - Structure, Echo String operations String processing The function s t r converts other types of data into a string. The concatenation operator + joins two strings to form a single string, The ith element of a string m y _ s t r i n g can be access via m y _ s t r i n g [ i ]. Note that strings are immutable (cannot be changed). Substrings of m y _ s t r i n g can be accessed via slicing . Lecture examples - Strings, Dollars and Cents One, Dollars and Cents Two More examples - Operations, Input Checking, Initials Drawing text Interactive drawing The method d r a w _ t e x t draws a string when given a position (lower left corner), a font size and a color. The method d r a w _ c i r c l e (see "More examples" below) draws a circle at a given point with a given radius in pixels. To draw a point, draw a circle of radius one. The method d r a w _ l i n e (see "More examples" below) draws a line between two points. The method d r a w _ p o l y g o n (see "More examples" below) draws a sequence of points (enclosed in square brackets and separated by commas) as a closed polygon. Colors for drawing methods can be specified as HTML color strings; " W h i t e " ," R e d " ," G r e e n " ,
. . .
Lecture examples - Interactive Drawing More examples - Shapes, Pictures, Hidden Picture
https://class.coursera.org/interactivepython-002/wiki/view?page=week3 1/2
10/05/2013
Timers Timers Timers are another component of SimpleGUI that generate regularly timed events. Users create a timer using c r e a t e _ t i m e r with a specified interval and event handler. The timer calls its associated event handler regularly at the given interval. A timer t is started with t . s t a r t ( ) and is stopped by t . s t o p ( ). Lecture examples - Timers More examples - Blinking Text, Reaction Time Programming Tips Week 3 (pt. 1), Week 3 (pt. 2)
Created Wed 5 Sep 2012 1:35 PM PDT -0700 Last Modified Fri 26 Oct 2012 12:36 PM PDT -0700
https://class.coursera.org/interactivepython-002/wiki/view?page=week3
2/2