Event Loops and GUI Intro2CS – weeks 11-12.

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

A graphical user interface (GUI) is a pictorial interface to a program. A good GUI can make programs easier to use by providing them with a consistent.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
CS 112 GUI 06 May 2008 Bilkent. Java GUI API Containers: ◦ contain other GUI components. E.g, Window, Panel, Applet, Frame Dialog. Components: ◦ Buttons,
Graphical User Interfaces A Quick Outlook. Interface Many methods to create and “interface” with the user 2 most common interface methods: – Console –
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Welcome to CIS 083 ! Events CIS 068.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Introduction to Windows Programming
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Computer Science [3] Java Programming II - Laboratory Course Lab 4: Common GUI Event Types and Listener Interfaces Layout Mangers Faculty of Engineering.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
Chapter 3 - VB.NET by Schneider1 Chapter 3 – Fundamentals of Programming in VB.NET Part I VB.NET Controls VB.NET Events.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
Scratch Programming Cards
Events and Event Handling
Java FX: Scene Builder.
EE 200 Design Tools Laboratory 14
Working in the Forms Developer Environment
Topics Graphical User Interfaces Using the tkinter Module
CompSci 230 S Software Construction
PYGAME.
Chapter Topics 15.1 Graphical User Interfaces
Event-driven programming
Chapter 8: Writing Graphical User Interfaces
Event loops 16-Jun-18.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Lecture 27 Creating Custom GUIs
Event Driven Programming Dick Steflik
Understanding an App’s Architecture
Lecture 28 Concurrent, Responsive GUIs
Understand Windows Forms Applications and Console-based Applications
Introduction to Events
Ellen Walker Hiram College
GUI Programming III: Events
Chap 7. Building Java Graphical User Interfaces
Chapter 2: GUI API Chapter 2.
Graphical User Interfaces -- Introduction
Fundamentals of Python: From First Programs Through Data Structures
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
Event Driven Programming
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
EE 422C Java FX.
Introduction to Object-Oriented Programming
GUIS: Graphical User Interfaces
Introduction to Computing Using Java
Event loops.
Tutorial 6 Creating Dynamic Pages
Event Driven Programming
Android Topics UI Thread and Limited processing resources
Event loops 17-Jan-19.
Event loops 17-Jan-19.
Review: Applying Computer Basics
Steps to Creating a GUI Interface
Topics Graphical User Interfaces Using the tkinter Module
Event loops 8-Apr-19.
Tonga Institute of Higher Education
Event loops.
Event loops.
Event loops 19-Aug-19.
Presentation transcript:

Event Loops and GUI Intro2CS – weeks 11-12

The taxi dispatcher Imagine a taxi cab dispatcher. His job is: to keep track of the location of taxis to answer requests for taxis (and dispatch a taxi) Most of the time he is bored.

How do we describe his job? When a taxi reports dropping off a passenger: if customers are waiting, send cab Else add cab to “waiting cabs” list When a customer calls in: If there are waiting taxis: send a taxi Else add the customer to the waiting customers list Notice that we are describing the job of the dispatcher when meaningful events happen

Did something new happen? The event loop Programs often sit around waiting for input. Did something new happen? Yes No React (run some code) Wait a bit

Event loops External thread or User activity Event Queue Is there an event in the queue? Yes No Handle event Wait a bit

Graphical User Interfaces (GUI) GUI programs are usually constructed with an event loop. It is already implemented for you. The GUI package we will use (comes with every python distribution) Create a window Create a button Set location of the button in the window and make it visible Start the event loop. You MUST do this.

Graphical User Interfaces (GUI) As program runs, execution stays with the event loop. Your code runs only when events occur. The user can freely interact with the GUI. Resize window, click button, close window…

Widgets There are many types of widgets

Many widgets… You can create GUIs just like any “windows” program you know. Freely control color, fonts, behavior when resizing etc. Impossible to cover it all in class. Search online for details! http://effbot.org/tkinterbook/tkinter-index.htm

GUI programs Two main things to take care of: Adding components and making it look “okay” Adding behavior. (We will focus on behavior) We will be defining events. What to do when things happen.

A class to handle our GUI Bind an event to a function We can do it with lambda expressions too! Create and run everything

Events General events Mouse clicks, Keys getting pressed Focus changes Windows got resized, or somehow changed … Action events from widgets Button widget clicked List selections changed Sliders moved

What to do when button pressed

We want to get the balls to move all the time on the screen. Writing a loop to do it would be bad. (WHY?) Instead: Ask the event loop to add an event in 10 milisecs that will call this method

Mouse button events

Layout Pack can be asked to place things at the top,bottom,right or left (top is the default).

Layout Pack can be asked to place things at the top,bottom,right or left (top is the default). Things that are packed later will be in the remaining “cavity” Two One

Using frames to organize things

grid

Recap (1) Container configuration More configuration Even more configuration

Recap (2)

What to do when a user presses an operator What to do when a user presses an operator? User Pressed: Display: When an operator is pressed we apply the previous operator to old + new number & store the result. 123 + 321 2 = × 123 123 321 444 2 888

… Using many tools A closure, with a lambda expression, That is used as an event handler.