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 create_frame. (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 set_draw_handler.
  • The draw handler can modify the canvas via simple draw operations defined in SimplGUI
  • Lecture examples - Canvas and Drawing
  • More examples - StructureEcho
String operations — String processing
  • The function str 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 my_string can be access via my_string[i]. Note that strings are immutable (cannot be changed).
  • Substrings of my_string can be accessed via slicing .
  • Lecture examples - StringsDollars and Cents OneDollars and Cents Two
  • More examples - OperationsInput CheckingInitials
Drawing text — Interactive drawing
  • The method draw_text draws a string when given a position (lower left corner), a font size and a color.
  • The method draw_circle (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 draw_line (see "More examples" below) draws a line between two points.
  • The method draw_polygon (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; "White", "Red", "Green", ...
  • Lecture examples - DrawingInteractive Drawing
  • More examples - ShapesPicturesHidden Picture
Timers — Timers
  • Timers are another component of SimpleGUI that generate regularly timed events.
  • Users create a timer using create_timer 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.start() and is stopped by t.stop().
  • Lecture examples - Timers
  • More examples - Blinking TextReaction Time

Programming Tips — Week 3 (pt. 1)Week 3 (pt. 2)

from: https://class.coursera.org/interactivepython-005/wiki/view?page=week3

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值