EVENT-DRIVEN PROGRAMMING. โปรแกรมและอุปกรณ์ส่วนมากที่ใช้ใน ชีวิตประจำวัน จะตอบสนองกับเหตุการณ์ที่ เกิดขึ้น ตัวอย่างของเหตุการณ์ อาทิ การเคลื่อน หรือ คลิกเมาส์

Slides:



Advertisements
Similar presentations
Microsoft ® Word 2010 Training Create your first Word document II.
Advertisements

Keyboard Techniques.
Intro to Computers!.
Operational & Function Keys Notes 2
Microsoft® Small Basic
Machine Parts and Related Terms. monitor The TV-like piece of equipment used to display text, data, and graphic images on screen.
 Use the Left and Right arrow keys or the Page Up and Page Down keys to move between the pages. You can also click on the pages to move forward.  To.
Word Lesson 1 Microsoft Word Basics
Microsoft® Small Basic
Microsoft Word 2010 Lesson 1: Introduction to Word.
Microsoft ® Word 2010 Training Create your first Word document II.
Access - Project 1 l What Is a Database? –A Collection of Data –Organized in a manner to allow: »Access »Retrieval »Use of That Data.
Copyright 2003, Paradigm Publishing Inc. CHAPTER 1 BACKNEXTEND 1-1 LINKS TO OBJECTIVES Worksheet Elements Create, Save, and Print a Worksheet Create, Save,
Copyright 2007, Paradigm Publishing Inc. POWERPOINT 2007 CHAPTER 1 BACKNEXTEND 1-1 LINKS TO OBJECTIVES Create Presentation Open, Save, Run, Print, Close,Delete.
XP New Perspectives on Microsoft Office Word 2003 Tutorial 1 1 Microsoft Office Word 2003 Tutorial 1 – Creating a Document.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
XP 1 Microsoft Office Word 2003 Tutorial 1 – Creating a Document.
Key Applications Module Lesson 12 — Word Essentials
Conversational Computers
Creating FrontPage Tasks The task view allows you to add information about what you want to accomplish when creating your Web site.
Computer System Examples? Input Output Devices System Unit Devices
Power Point EDU 271 Microsoft PowerPoint is a powerful tool to create professional looking presentations and slide shows. PowerPoint allows you to construct.
Microsoft Office Word 2003 Tutorial 1 Creating a Document.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Pasewark & Pasewark 1 Word Lesson 1 Word Basics Microsoft Office 2007: Introductory.
XP New Perspectives on Microsoft Word 2002 Tutorial 21 Microsoft Word 2002 Tutorial 2 – Editing and Formatting a Document.
MICROSOFT WORD GETTING STARTED WITH WORD. CONTENTS 1.STARTING THE PROGRAMSTARTING THE PROGRAM 2.BASIC TEXT EDITINGBASIC TEXT EDITING 3.SAVING A DOCUMENTSAVING.
Chapter 4—Creating your First Document
October 15 click! 1 Computer Basics Kitsap Regional Library.
Get to Know Your Keyboard. Operational Keys Escape (Esc) – allows you to exit unwanted menus and dialog boxes Tab – used to indent; moves the cursor 5.
XP 1 Microsoft Word 2002 Tutorial 1 – Creating a Document.
Microsoft Word 2000 Presentation 2 Microsoft Word Topics  Tools –Spelling/Grammar Check –Thesaurus –AutoCorrect –Word Count –Change Case –Background.
WORD – CHAPTER 1 1.formatting toolbar 2.minimize button 3.office assistant 4.horizontal scroll bar 5.screen tip 6.menu bar 7.restore button.
Keyboard and Events. What about the keyboard? Keyboard inputs can be used in many ways---not just for text The boolean variable keyPressed is true if.
© 2010 South-Western / Cengage Learning Century 21 Keyboarding  Cycle 1  Office Features 1.
Hello, little turtles. Hello, little turtles! There are many modules in Python that provide very powerful feature that we can use in our own program.
Unit 1. Alternate Key Also called ALT key Executes commands with other key(s)
Copyright 2002, Paradigm Publishing Inc. CHAPTER 1 BACKNEXTEND 1-1 LINKS TO OBJECTIVES Worksheet Elements Worksheet Elements Worksheet Area Elements Worksheet.
CS130 Project 1 A simple VB application ("project" or program): user enters amount of sales then clicks the "Calculate button", the application displays.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.
CS1Q Computer Systems Lecture 11 Simon Gay. Lecture 11CS1Q Computer Systems - Simon Gay 2 The D FlipFlop The RS flipflop stores one bit of information.
Lesson: 2 Common Features and Commands After completing this lesson, you will be able to: Identify the main components of the user interface. Identify.
Computer Vocabulary Computer
Instructions As the slides are displayed, discuss each slide to promote the correct keyboarding position and the proper use of various keys on the keyboard.
1 Word Lesson 1 Microsoft Word Basics Microsoft Office 2010 Introductory Pasewark & Pasewark.
Word 2010 Text Basics In this lesson you'll learn the basics of working with text, including how to insert, delete, select, copy, cut, paste, and replace.
Microsoft Office 2007: Introductory Pasewark & Pasewark 1.
Copyright 2007, Paradigm Publishing Inc. EXCEL 2007 Chapter 1 BACKNEXTEND 1-1 LINKS TO OBJECTIVES Identify Elements of an Excel WorkbookIdentify Elements.
EXPLORING THE WINDOWS SECTION PART 1 MOAC Lesson 1.
COMPUTER LITERACY 1 TRANSITION PLUS BASIC COMPUTER USE PART 1.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Key Applications Module Lesson 12 — Word Essentials Computer Literacy BASICS.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
COMPUTER INPUT DEVICE Keyboard. Keyboard cont…… Print Screen Print contents of screen Pause/Break Terminate/Interrupt Scroll Lock Modify behavior of the.
QWERTYUIOP ?. Parts & Layout of the 1. Main Keypad 2. Functions Keys 3. Modifier Keys 4. Legacy keys 5. Navigation Keys 6. Numeric Keypad 7. Indicator.
Keyboarding Slideshow
Mouse & Keyboard Basics
Kitsap Regional Library
Key Applications Module Lesson 12 — Word Essentials
Kitsap Regional Library
Keyboarding.
Microsoft Excel 2007 – Level 1
Key Applications Module Lesson 12 — Word Essentials
Keyboarding Vocabulary
Creating a Simple Game in Scratch
KEYBOARDING KEY TERMS.
Keyboarding Vocabulary
Presentation transcript:

EVENT-DRIVEN PROGRAMMING

โปรแกรมและอุปกรณ์ส่วนมากที่ใช้ใน ชีวิตประจำวัน จะตอบสนองกับเหตุการณ์ที่ เกิดขึ้น ตัวอย่างของเหตุการณ์ อาทิ การเคลื่อน หรือ คลิกเมาส์

Keypress Events

Press Up Key

Press Left Key

listen method We need the call to the window’s listen method, otherwise it won’t notice our keypresses. We named our handler functions h1, h2 and so on, but we can choose better names. The handlers can be arbitrarily complex functions that call other functions, etc

Pressing the q key on the keyboard calls function h4 (because we bound the q key to h4 ). While executing h4, the window’s bye method closes the turtle window, which causes the window’s mainloop call to end its execution.

We can refer to keys on the keyboard by their character code (as we did in the program), or by their symbolic names. Some of the symbolic names to try are Cancel, BackSpace, Tab, Enter, Shift, Control, Alt, Pause, Caps_Lock, Escape, Page Up, Page Down End, Home, Left, Up, Right, Down, Print, Insert, Delete, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, Num_Lock, and Scroll_Lock.

Mouse events A mouse event is a bit different from a keypress event because its handler needs two parameters to receive x,y coordinate information telling us where the mouse was when the event occurred.

There is a goto method, this allows us to move the turtle to an absolute coordinate position. (Most of the examples that we’ve seen so far move the turtle relative to where it currently is). So what this program does is move the turtle (and draw a line) to wherever the mouse is clicked. Try it out!

wn.title("Got click at coords {0}, {1}".format(x, y)) Because we can easily change the text in the window’s title bar, it is a useful place to display occasional debugging or status information. (Of course, this is not the real purpose of the window title!) But there is more!

Turtle handlers Not only can the window receive mouse events: individual turtles can also have their own handlers for mouse clicks. The turtle that “receives” the click event will be the one under the mouse. So we’ll create two turtles. Each will bind a handler to its own onclick event. And the two handlers can do different things for their turtles.

Automatic events from a timer Alarm clocks, kitchen timers, and thermonuclear bombs in James Bond movies are set to create an “automatic” event after a certain interval. The turtle module in Python has a timer that can cause an event when its time is up.

state machines A state machine is a system that can be in one of a few different states. We draw a state diagram to represent the machine, where each state is drawn as a circle or an ellipse. Certain events occur which cause the system to leave one state and transition into a different state. These state transitions are usually drawn as an arrow on the diagram.

State machines This idea is not new: when first turning on a cellphone, it goes into a state which we could call “Awaiting PIN”. When the correct PIN is entered, it transitions into a different state—say “Ready”. Then we could lock the phone, and it would enter a “Locked” state, and so on.

State machines A simple state machine that we encounter often is a traffic light. Here is a state diagram which shows that the machine continually cycles through three different states, which we’ve numbered 0, 1 and 2.

Traffic lights We’re going to build a program that uses a turtle to simulate the traffic lights. There are three lessons here. The first shows off some different ways to use our turtles. The second demonstrates how we would program a state machine in Python, by using a variable to keep track of the current state, and a number of different if statements to inspect the current state, and take the actions as we change to a different state. The third lesson is to use events from the keyboard to trigger the state changes.

A kind of state machine A traffic light is a kind of state machine with three states, Green, Orange, Red. We number these states 0, 1, 2 When the machine changes state, we change tess’ position and her fillcolor. This variable holds the current state of the machine state_num = 0

Press the Space bar key to change to a different state