1 of 10

LISTENING FOR INPUTS

Expanding our repertoire beyond the command line

1

2 of 10

INPUT AND EVENTS

2

Considering different ways of executing programs

NOTE: You will not be tested on inputs and events, but these slides will help you with Project 1.

3 of 10

INPUTS AND EVENTS

3

Many ways that you interact w/computers do not involve the command line. For example:

  • Code can executed based on user input
  • Code can run as the result of scheduling regular tasks that are controlled by the operating system
  • There are also processes, or threads that are running in the background of your computer that are listening for certain kinds of events, and if they happen, then code executes

4 of 10

EXAMPLES OF INPUTS

4

There are many different kinds of inputs, which should all be very familiar to you:�

  • Clicking a button
  • Typing on the keyboard
  • Dragging, swiping, rotating
  • Using sensors
  • Reading data from files or databases
  • Double-clicking a program to start it

5 of 10

EVENTS: WAYS OF RESPONDING TO USER INPUT

5

Events allow programs to listen to particular events (clicks, drags, etc.) and execute parts of a program based on the input. Events have two parts:

  1. An event listener, which can detect that an event has occurred and the nature of it. Listeners notify your program that something has happened.
  2. An event handler (the function), which is the block of code that responds to an event when is triggered by executing a code block. Event handlers are sometimes called “callbacks.

6 of 10

ASIDE: READING TECHNICAL DOCUMENTATION

6

At this point in the course, I encourage you to begin trying to read the technical documentation that is associated with various Python modules and functions. We will have a lesson on interpreting documentation after the quiz/exam

7 of 10

ASIDE: READING TECHNICAL DOCUMENTATION

7

Caveat: The tkinter documentation was last updated in 2005, using an old version of Python (2.x — you all are using Python ~3.7). Some things have changed:

Python 2.x

Python 3.x

print ‘Hello world!’

print(‘Hello world!’)

import Tkinter # title case

import tkinter # lowercase

mainloop()

master.mainloop()

8 of 10

ASIDE: LEARNING TO WORK WITH MODULES

8

Every module / library is its own unique snowflake, filled with both amazing functionality and things that make no intuitive sense. Example (tkinter):

  1. Who thinks of making a circle in terms of specifying the top left and bottom right boundary? Nonsense?!
  2. ...but isn’t it great that we can make an animation relatively easily?

BIG IDEA: Learning to work with third-party modules and �technical documentation is the key skill you’re learning

9 of 10

Examples of UI Input Events

9

  • Buttons
  • Select Menus
  • Textboxes
  • Sliders
  • Interactions with the Canvas

As you begin to arrange and connect these interface widgets together and connect them to executable functions, you can actually create your own Windows / Mac Desktop applications that others might download and use!

10 of 10

Graphics UI Demos / Activities

/event_demos/

10