© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 9 GUI Programming Using Tkinter 1.

Slides:



Advertisements
Similar presentations
Getting Started with PowerPoint
Advertisements

JustinMind: Dynamic Panels
Noadswood Science,  To know how to use Python to produce windows and colours along with specified co-ordinates Sunday, April 12, 2015.
Learning PowerPoint Starting and Customizing a PowerPoint Slide Show.
Chapter 2 Publishing a Trifold Brochure
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 2 More Controls.
© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
© by Pearson Education, Inc. All Rights Reserved. continued …
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
Create slices and hotspots Create links in Web pages Create rollovers from slices Create basic animation Add tweening symbol instances to create animation.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L03 (Chapter 15) Creating.
Slide Transitions Slide Show, Slide Transition opens Slide Transition task pane Practice each option setting to select the transition style, its speed,
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
With Microsoft Access 2010 © 2011 Pearson Education, Inc. Publishing as Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Access.
Word Processing basics
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Microsoft Word 2010 Chapter 1 Creating, Formatting, and Editing a Word Document with Pictures.
WEEK Introduction to GUI programming. Introduction Each data type can represent a certain set of values, and each had a set of associated operations.
COMPSCI 101 Principles of Programming
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 26 – CheckWriter Application Introducing Graphics.
Chapter 14. Copyright 2003, Paradigm Publishing Inc. CHAPTER 14 BACKNEXTEND 14-2 LINKS TO OBJECTIVES Add Borders with Borders Button Add Borders with.
Chapter 2 More Controls Programming in C#. NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
The University of Texas – Pan American
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 13 Creating User.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Chapter 2 - More Controls More controls – Text boxes - used for user input – Frames - containers to group items – check boxes - user select an option -
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
PYTHON GUI PROGRAMMING
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 3.1 Test-Driving the Welcome Application 3.2.
Chapter 2 P. 1 Introducing more controls (on the Toolbox) (Fig. 2.1) - Text box - Frame - Option button - Check box - Image Example P. 44 Figure 2.2 Message.
Lesson 10 Using AutoShapes, WordArt, and Comments Lesson 10 Using AutoShapes, WordArt, and Comments.
Microsoft FrontPage 2003 Illustrated Complete Creating a Form.
Chapter 2 – Introduction to the Visual Studio .NET IDE
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.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
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.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 41 JavaServer Face.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 2 More Controls.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
CSC 1010 Programming for All Lecture 7 Input, Output & Graphics.
Object-Oriented Application Development Using VB.NET 1 Chapter 10 VB.NET GUI Components Overview.
Creating visual interfaces in python
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
CMPF114 Computer Literacy Chapter 3 The Visual Basic Environment 1.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 14 JavaFX Basics.
Chapter 20. Copyright 2003, Paradigm Publishing Inc. CHAPTER 20 BACKNEXTEND 20-2 LINKS TO OBJECTIVES Create, Format, and Customize Drawn Objects Create,
Chapter 2 More Controls Programming in C#. NET Objectives Use text boxes, group boxes, check boxes, radio buttons, and picture boxes effectively.
MATLAB and SimulinkLecture 61 To days Outline Graphical User Interface (GUI) Exercise on this days topics.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
COMPSA Exam Prep Session by Paul Allison On: April 8th from 1:30-3:00 Location TBA Winter 2016CISC101 - Prof. McLeod1.
 You won’t write a single line of program code.  Instead, you’ll use visual programming techniques.  Visual Studio processes your actions (such as mouse.
Topics Graphical User Interfaces Using the tkinter Module
Microsoft Access 2007 – Level 2
Chapter 21 – Graphics/Tk Outline 21.1 Introduction 21.2 GD Module: Creating Simple Shapes 21.3 GD Module: Image Manipulation 21.4 Chart Module 21.5 Introduction.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Creating, Formatting, and Editing a Word Document with Pictures
GUI Using Python.
Fundamentals of Python: From First Programs Through Data Structures
This Week: Tkinter for GUI Interfaces Some examples
Chapter 2 – Introduction to the Visual Studio .NET IDE
Signature: Microsoft Word 2003
Topics Graphical User Interfaces Using the tkinter Module
Chapter 4 Enhancing the Graphical User Interface
In this chapter, you will learn the following:
Presentation transcript:

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 9 GUI Programming Using Tkinter 1

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Motivations Tkinter is not only a useful tool for developing GUI projects, but also a valuable pedagogical tool for learning object-oriented programming. 2

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Objectives To create a simple GUI application using Tkinter (§9.2). To process events using callback functions bound to widget’s command option (§9.3). To use a variety of widget classes to create widgets (§9.4). To use labels, entries, buttons, check buttons, radio buttons, messages, and texts to create graphical user interfaces (§9.4). To draw lines, rectangles, ovals, polygons, and arcs and display strings in a canvas (§9.5). To encapsulate data fields to make classes easy to maintain (§9.5). To layout widgets in a container using the geometry managers (§9.6). To pack widgets side-by-side or a top of each other using the pack manager (§9.6.1). To layout widgets in a grid using the grid manager (§9.6.2). To place widgets in absolute locations using the manager (§9.6.3). To use containers to group widgets to achieve desired layout (§9.7). To use images in widgets (§9.8). To create applications using menus (§9.9). To create applications using popup menus (§9.10). To bind mouse and key event on a widget to a callback function for processing events (§9.11). To develop animations (§9.12). To use scrollbars to scroll contents in a Text widget (§9.13). To use standard dialog boxes for display messages and receive input (§9.14). 3

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Getting Started with Tkinter Getting started with Tkinter with a simple example. 4 SimpleGUIRun

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Processing Events window.mainloop() # Create an event loop The statement creates an event loop. The event loop processes the events continuously. 5 ProcessButtonEvent Run

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. The Widget Classes 6

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Color and Font To specify a color, you can either use a color name such as red, yellow, green, blue, white, black, purple, etc, or explicitly specify the red, green, and blue (RGB) color components using a string #RRGGBB, where RR, GG, BB are hexadecimal representations of the red, green and blue values, respectively. 7 "Times 10 bold" "Helvetica 10 bold italic" "Courier New 20 bold italic" "Courier New 20 bold italic over strike underline"

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Text Formatting The text in a label and a button is centered by default. You can change it by using the justify option with values LEFT, CENTER, or RIGHT. You can also display the text in multiple lines by inserting the newline character \n to separate texts. 8

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Mouse Cursor You can set a mouse cursor by using the cursor option with values such as "arrow" (default), "circle", "cross" "plus", etc. 9

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Change Properties widgetName["propertyName] = newPropertyValue 10 btShowOrHide = Button(window, text = "Show", bg = "white") btShowOrHide["text"] = "Hide" btShowOrHide["bg"] = "red" btShowOrHide["fg"] = "#AB84F9" # Change fg color to #AB84F9 btShowOrHide["cursor"] = "plus" # Change mouse cursor to plus

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Widget Demo 11 WidgetsDemoRun

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Canvas Canvas can be used to display shapes. You can use the method such as create_rectangle, create_oval, create_arc, create_polygon, and create_line to draw a rectangle, oval, arc, polygon, and line on a canvas. 12

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Canvas Demo 13 CanvasDemoRun

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Drawing Methods 14

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Geometry Managers Grid Manager Pack Manager Place Manager Since each manager has its own style of placing the widget, it is not a good practice to mix the managers for the widgets in the same container. You can use a frame as a subcontainer to achieve desired layout. 15

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Grid Managers 16 GridManagerDemoRun

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Pack Managers 17 PackManagerDemo2Run PackManagerDemo1Run

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Place Managers 18 PlaceManagerDemoRun

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Case Study: Loan Calculator 19 LoanCalculatorRun

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Display Images You can add an image in a label, button, check button, and radio button. To create an image, use the PhotoImage class as follows: photo = PhotoImage(file = imagefilename) The image file must be GIF. You can use a conversion utility to convert image files in other format into GIF. 20

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Image Example 21 ImageDemoRun

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Menus Tkinter provides a comprehensive solution for building graphical user interfaces. 22 MenuDemoRun

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Popup Menus 23 PopupMenuDemoRun

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Mouse and Key Events widget.bind(event, handler) def popup(event): menu.post(event.x_root, event.y_root) 24

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Events 25

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Event Properties 26

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Mouse Key Event Demo 27 MouseKeyEventDemoRun

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Control Circle Demo 28 ControlCircleRun

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Animations 29 AnimationDemoRun

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Control Animations 30 ControlAnimationRun

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Scrollbar 31 ScrollTextRun

© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Standard Dialogs 32 DialogDemo Run