An Introduction to Interactive Programming in Python - Week two

Event handlers — Event-driven programming
  • Event handlers (also called callbacks) are functions registered to an event such as a button click, keyboard press or mouse click.
  • Event handlers react to the event by changing the state (collection of information) encoded in the program.
  • Lecture examples - Events
  • More examples - None
Local variables — Local vs. global variables
  • Assignment to a variable inside a Python function creates a local variable.
  • The scope of variable (portion of the program where the value of the variable can be accessed) is the body of function.
  • Lecture examples - Local vs Global
  • More examples - Example
Global variables — Local vs. global variables
  • Variables defined outside functions are global variables. Their values may be accessed inside functions without declaration.
  • To modify to a global variable inside a function, the variable must be declared inside the function using the keyword global.
  • Global variables are a convenient (but dangerous) way for event handlers to share information in event-driven programming.
  • Lecture examples - Local vs Global
  • More examples - Example
SimpleGUI module — SimpleGUI
  • Special module for CodeSkulptor that supports 2D interactive applications. The Docs button links to documentation for SimpleGUI.
  • SimpleGUI allows creations of frames and timers as well as loading sounds and images.
  • Frames include a control panel (with buttons and input fields), a status area (for monitoring keyboard and mouse events) and a canvas (with simple 2D drawing operations).
  • Lecture examples - SimpleGUITemplate
  • More examples - LayoutFrameErrors
Buttons — Buttons Input fields — Input fields
  • Input fields may be created (and their event handlers registered) via add_input.
  • Input fields are positioned linearly (top/down) in the control panel in their order of creation.
  • The event handlers for the input field take a single parameter that is the text string entered.
  • Lecture examples - CalculatorInput Fields
  • More examples - StructureFunctionsFactoringSilly Words

Programming Tips  Week 2

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章