Computer Science 111 Fundamentals of Programming I User Interfaces

Slides:



Advertisements
Similar presentations
Chapter 18 Building the user interface. This chapter discusses n Javas graphical user interface. n Swing: an enhancement of a library called the Abstract.
Advertisements

Computer Science 112 Fundamentals of Programming II User Interfaces
Designing a Graphical User Interface (GUI) 10 IST – Topic 6.
An Introduction to Visual Basic Terms & Concepts.
User Interface. What is a User Interface  A user interface is a link between the user and the computer. It allows the user and the computer to communicate.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Part 3: Design Days 15, 19, 21, 23 Chapter 8: Work Reengineering and Conceptual Design Chapter 9: Design Guidance and Design Rationale Chapter 10: Interaction.
Chapter 7 Improving the User Interface
Computer Science 111 Fundamentals of Programming I User Interfaces Introduction to GUI programming.
AS Level ICT Selection and use of appropriate software: Interfaces.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Computer Science 112 Fundamentals of Programming II Graphics Programming.
Computer Science 111 Fundamentals of Programming I Model/View/Controller and Data model design.
PC204 Lecture 9 Conrad Huang Genentech Hall, N453A x
CHAPTER TWO INTRODUCTION TO VISUAL BASIC © Prepared By: Razif Razali 1.
© Paradigm Publishing Inc. 4-1 OPERATING SYSTEMS.
Computer Science 112 Fundamentals of Programming II Command Buttons and Responding to Events.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 20 Graphical User Interface (GUI)
Python Programming Graphical User Interfaces Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Computing Science 1P Lecture 17: Friday 23 rd February Simon Gay Department of Computing Science University of Glasgow 2006/07.
Graphical User Interface You will be used to using programs that have a graphical user interface (GUI). So far you have been writing programs that have.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
Guide to Programming with Python
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
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.
Computer Science 112 Fundamentals of Programming II Data Fields for I/O and Message Boxes for Error Recovery.
Programming Logic and Design Seventh Edition Chapter 12 Event-Driven GUI Programming, Multithreading, and Animation.
CSC 222: Object-Oriented Programming
Topics Graphical User Interfaces Using the tkinter Module
CompSci 230 S Software Construction
Introduction to Programming and Visual Basic
Computer Science 111 Fundamentals of Programming I
Chapter Topics 15.1 Graphical User Interfaces
11.10 Human Computer Interface
Event loops 16-Jun-18.
Event Driven Programming Dick Steflik
1. Introduction to Visual Basic
Fundamentals of Programming I The Model/View/Controller Design Pattern
An Introduction to Visual Basic
Computer Science 112 Fundamentals of Programming II GUIs II:
Module 1.1 Introduction to computers
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Fundamentals of Python: From First Programs Through Data Structures
Tkinter Python User Interface
Tkinter GUIs Computer Science and Software Engineering
Fundamentals of Python: First Programs Second Edition
Introduction to Computing Using Java
Social Media And Global Computing Introduction to Visual Studio
Tonga Institute of Higher Education
Event loops.
UNIT-5.
Event loops 17-Jan-19.
Event loops 17-Jan-19.
Fundamentals of Programming I Windows, Labels, and Command Buttons
Computer Science 111 Fundamentals of Programming I Text Areas
Fundamentals of Programming I The Model/View/Controller Design Pattern
Computer Science 111 Fundamentals of Programming I
Chapter 15: GUI Applications & Event-Driven Programming
Event loops 8-Apr-19.
The University of Texas – Pan American
Event loops.
Event loops.
Event loops 19-Aug-19.
An Introduction to the Windows Operating System
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

Computer Science 111 Fundamentals of Programming I User Interfaces Introduction to GUI programming

What Is a User Interface? A set of hardware devices (touch screen, monitor, keyboard, mouse, microphone, speakers) Software (input/output functions) Allows human beings to use a computer effectively Inputs UI Computation Outputs

Types of User Interfaces ZUI (zoomable user interface) GUI (graphical user interface) TUI (terminal-based user interface) Inputs UI Computation Outputs

Terminal-Based User Interface (TUI) Supports input via the keyboard and output via the monitor In Python, the I/O functions are input and print print("Tax Calculator\n") RATE = .15 EXEMPTION_AMOUNT = 3500.0 income = float(input("Please enter your income: $")) exemptions = int(input("Please enter the number of exemptions: ")) tax = max(0.0, (income - exemptions * EXEMPTION_AMOUNT) * RATE) print("Your total tax is $%0.2f." % tax)

Terminal-Based User Interface (TUI) Supports input via the keyboard and output via the monitor In Python, the I/O functions are input and print print("Tax Calculator\n") RATE = .15 EXEMPTION_AMOUNT = 3500.0 income = float(input("Please enter your income: $")) exemptions = int(input("Please enter the number of exemptions: ")) tax = max(0.0, (income - exemptions * EXEMPTION_AMOUNT) * RATE) print("Your total tax is $%0.2f." % tax)

Problems with a TUI Must enter inputs in a certain order Cannot back up to correct input mistakes or change one’s mind Must re-enter all inputs to change just one I/O restricted to text

Graphical User Interface (GUI) Supports input via the keyboard Can output text and also graphical shapes representing desktop elements, such as windows, command buttons, data fields, and drop-down menus (also called “widgets”) Supports direct manipulation of desktop elements via the mouse or touchscreen

TUI vs GUI Non-programmers (the 99%) do not use a TUI, they use a GUI Only programmers (the 1%) use a TUI (and also a GUI) Most beginning programmers program to a TUI, not a GUI

Models of Computation TUI GUI Obtain user inputs Perform computations Print results Layout and pop up the window Wait for user events Handle a user event Goto step 2 The model of computation for a GUI program is more complex than that of a TUI program

Programming a GUI Most modern programming languages (like Python and Java) include packages or modules for programming a GUI In Python, this module is called tkinter

GUI Resources in Python tkinter http://docs.python.org/py3k/library/tkinter.html#module-tkinter breezypythongui http://home.wlu.edu/~lambertk/breezypythongui/index.html Code for all examples in Chapter 8 is in the Resources folder on Sakai.

What Is breezypythongui? A module of classes and functions that makes GUI programming with tkinter easy for beginners The module is free and open-source A tutorial and sample programs are available at the breezypythongui Web site

A First GUI Program: Hello World from breezypythongui import EasyFrame Import the abstract window class

A First GUI Program: Hello World from breezypythongui import EasyFrame class LabelDemo(EasyFrame): """Displays a greeting in a window.""" Define a subclass to specialize it for this application

A First GUI Program: Hello World from breezypythongui import EasyFrame class LabelDemo(EasyFrame): """Displays a greeting in a window.""" def __init__(self): """Sets up the window and the label.""" EasyFrame.__init__(self) self.addLabel(text = "Hello world!", row = 0, column = 0) Lay out the window and its widgets

A First GUI Program: Hello World from breezypythongui import EasyFrame class LabelDemo(EasyFrame): """Displays a greeting in a window.""" def __init__(self): """Sets up the window and the label.""" EasyFrame.__init__(self) self.addLabel(text = "Hello world!", row = 0, column = 0) # Instantiates and pops up the window. if __name__ == "__main__": LabelDemo().mainloop() Create and launch the application window

The Structure of Any GUI Program from breezypythongui import EasyFrame class <class name>(EasyFrame): def __init__(self): EasyFrame.__init__(self <optional args>) <code to set up widgets> <code to define event-handling methods> # Instantiates and pops up the window. if __name__ == "__main__": <class name>().mainloop()

Classes and Inheritance Inheritance: Class B inherits the attributes and operations of class A, and then adds some of its own; clients can run A’s methods as well as B’s methods A B = extends from <some module> import <parent class name> class <class name>(<parent class name>):

Classes and Inheritance It’s easiest to build a new class by extending an existing class In tkinter module Frame In breezypythongui module EasyFrame In labeldemo module LabelDemo from breezypythongui import EasyFrame class LabelDemo(EasyFrame):

Laying Out Widgets class LayoutDemo(EasyFrame): """Displays labels in the quadrants.""" def __init__(self): """Sets up the window and the labels.""" EasyFrame.__init__(self) self.addLabel(text = "(0, 0)", row = 0, column = 0) self.addLabel(text = "(0, 1)", row = 0, column = 1) self.addLabel(text = "(1, 0)", row = 1, column = 0) self.addLabel(text = "(1, 1)", row = 1, column = 1)

Alignment and Spanning def __init__(self): """Sets up the window and the labels.""" EasyFrame.__init__(self) self.addLabel(text = "(0, 0)", row = 0, column = 0, sticky = "NSEW") self.addLabel(text = "(0, 1)", row = 0, column = 1, self.addLabel(text = "(1, 0 and 1)", row = 1, column = 0, sticky = "NSEW", columnspan = 2)

For Next Time Check out the breezypythongui website Window attributes Labels Command buttons Responding to user events