Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.

Slides:



Advertisements
Similar presentations
Microsoft Visual Basic: Reloaded Chapter Five More on the Selection Structure.
Advertisements

CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Exploring Microsoft Access Chapter 8 Creating More Powerful Applications: Introduction to VBA By Robert T. Grauer Maryann Barber.
Lecture 15 Graphical User Interfaces (GUI’s). Objectives Provide a general set of concepts for GUI’s Layout manager GUI components GUI Design Guidelines.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Exploring Office Grauer and Barber 1 Creating More Powerful Applications: Introduction to VBA(Wk9)
Interaction Styles Interface Widgets. What are Interaction Styles?  A Collection of interface objects and associated techniques from which an interaction.
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
CST JavaScript Validating Form Data with JavaScript.
Slide 1 Chapter 2 Visual Basic Interface. Slide 2 Chapter 2 Windows GUI  A GUI is a graphical user interface.  The interface is what appears on the.
Visual Basic Chapter 1 Mr. Wangler.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
Guide to Programming with Python Chapter Ten GUI Development: The Mad Lib Program.
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
Chapter 8: Writing Graphical User Interfaces Visual Basic.NET Programming: From Problem Analysis to Program Design.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
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.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Exploring Microsoft Access Chapter 8 Creating More Powerful Applications: Introduction to VBA.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
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.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 9 GUI Programming Using Tkinter 1.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
How the Session Works Outline Practical on arrival Talk 1 Reflect on practical Clarify concepts Practical exercises at your own pace Talk 2: Further concepts.
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.
Topics Introduction Scene Graphs
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
GUI development with Matlab: GUI Front Panel Components GUI development with Matlab: Other GUI Components 1 Other GUI components In this section, we will.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing.
Object-Oriented Application Development Using VB.NET 1 Chapter 10 VB.NET GUI Components Overview.
Creating visual interfaces in python
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
CMPF114 Computer Literacy Chapter 3 The Visual Basic Environment 1.
Guide to Programming with Python
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 14 Event-Driven Programming with Graphical User Interfaces.
MATLAB and SimulinkLecture 61 To days Outline Graphical User Interface (GUI) Exercise on this days topics.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
Topics Graphical User Interfaces Using the tkinter Module
Graphical User Interfaces (GUIs)
Chapter Topics 15.1 Graphical User Interfaces
Section 17.1 Section 17.2 Add an audio file using HTML
Fundamentals of Python: From First Programs Through Data Structures
Topics Graphical User Interfaces Using the tkinter Module
Chapter 15: GUI Applications & Event-Driven Programming
The University of Texas – Pan American
Chapter 4 Enhancing the Graphical User Interface
TA: Nouf Al-Harbi NoufNaief.net :::
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Topics Graphical User Interfaces Using the tkinter Module Display Text with Label Widgets Organizing Widgets with Frames Button Widgets and Info Dialog Boxes Getting Input with the Entry Widget Using Labels as Output Fields Radio Buttons and Check Buttons

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Graphical User Interfaces User Interface: the part of the computer with which the user interacts Command line interface: displays a prompt and the user types a command that is then executed Graphical User Interface (GUI): allows users to interact with a program through graphical elements on the screen

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Graphical User Interfaces (cont’d.)

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Graphical User Interfaces (cont’d.) Dialog boxes: small windows that display information and allow the user to perform actions Responsible for most of the interaction through GUI User interacts with graphical elements such as icons, buttons, and slider bars

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

GUI Programs Are Event- Driven In text-based environments, programs determine the order in which things happen The user can only enter data in the order requested by the program GUI environment is event-driven The user determines the order in which things happen User causes events to take place and the program responds to the events

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Using the tkinter Module No GUI programming features built into Python tkinter module: allows you to create simple GUI programs Comes with Python Widget: graphical element that the user can interact with or view Presented by a GUI program

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Using the tkinter Module (cont’d.) Programs that use tkinter do not always run reliably under IDLE For best results run them from operating system command prompt Most programmers take an object- oriented approach when writing GUI programs __init__ method builds the GUI When an instance is created the GUI appears on the screen

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Display Text with Label Widgets Label widget: displays a single line of text in a window Made by creating an instance of tkinter module’s Label class Format: tkinter.Label(self.main_window, \ text = 'my text') First argument references the root widget, second argument shows text that should appear in label

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Display Text with Label Widgets (cont’d.) pack method: determines where a widget should be positioned and makes it visible when the main window is displayed Called for each widget in a window Receives an argument to specify positioning Positioning depends on the order in which widgets were added to the main window Valid arguments: side='top', side='left', side='right'

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Display Text with Label Widgets (cont’d.)

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Organizing Widgets with Frames Frame widget: container that holds other widgets Useful for organizing and arranging groups of widgets in a window The contained widgets are added to the frame widget which contains them Example: tkinter.Label(self.top_frame, \ text = 'hi')

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Organizing Widgets with Frames (cont’d.)

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Button Widgets and Info Dialog Boxes Button widget: widget that the user can click to cause an action to take place When creating a button can specify: Text to appear on the face of the button A callback function Callback function: function or method that executes when the user clicks the button Also known as an event handler

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Button Widgets and Info Dialog Boxes (cont’d.) Info dialog box: a dialog box that shows information to the user Format for creating an info dialog box: Import tkinter.messagebox module tkinter.messagebox.showinfo(title, \ message) title is displayed in dialog box’s title bar message is an informational string displayed in the main part of the dialog box

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Button Widgets and Info Dialog Boxes (cont’d.)

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Creating a Quit Button Quit button: closes the program when the user clicks it To create a quit button in Python: Create a Button widget Set the root widget’s destroy method as the callback function When the user clicks the button the destroy method is called and the program ends

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Getting Input with the Entry Widget Entry widget: rectangular area that the user can type text into Used to gather input in a GUI program Typically followed by a button for submitting the data The button’s callback function retrieves the data from the Entry widgets and processes it Entry widget’s get method: used to retrieve the data from an Entry widget Returns a string

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Getting Input with the Entry Widget (cont’d.)

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Using Labels as Output Fields Can use Label widgets to dynamically display output Used to replace info dialog box Create empty Label widget in main window, and write code that displays desired data in the label when a button is clicked

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Using Labels as Output Fields (cont’d.) StringVar class: tkinter module class that can be used along with Label widget to display data Create StringVar object and then create Label widget and associate it with the StringVar object Subsequently, any value stored in the StringVar object with automatically be displayed in the Label widget

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Using Labels as Output Fields (cont’d.)

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Radio Buttons and Check Buttons Radio button: small circle that appears filled when it is selected and appears empty when it is deselected Useful when you want the user to select one choice from several possible options Radiobutton widgets: created using tkinter module’s Radiobutton class Radiobutton widgets are mutually exclusive Only one radio button in a container may be selected at any given time

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Radio Buttons and Check Buttons (cont’d) IntVar class: a tkinter module class that can be used along with Radiobutton widgets Steps for use: Associate group of Radiobutton widgets with the same IntVar object Assign unique integer to each Radiobutton When a Radiobutton widgets is selected, its unique integer is stored in the IntVar object Can be used to select a default radio button

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Using Callback Functions with Radiobuttons You can specify a callback function with Radiobutton widgets Provide an argument command=self.my_method when creating the Radiobutton widget The command will execute immediately when the radio button is selected Replaces the need for a user to click OK or submit before determining which Radiobutton is selected

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Check Buttons Check button: small box with a label appearing next to it; check mark indicates when it is selected User is allowed to select any or all of the check buttons that are displayed in a group Not mutually exclusive Checkbutton widgets: created using tkinter module’s Checkbutton class Associate different IntVar object with each Checkbutton widget

Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Summary This chapter covered: Graphical user interfaces and their role as event-driven programs The tkinter module, including: Creating a GUI window Adding widgets to a GUI window Organizing widgets in frames Receiving input and providing output using widgets Creating buttons, check buttons, and radio buttons