GUI in Python Ismail Abumuhfouz.

Slides:



Advertisements
Similar presentations
Python Programming: An Introduction to Computer Science
Advertisements

Graphics Shapes. Setup for using graphics You have to import the graphics library You can use either “import graphics” or “from graphics import *” or.
Noadswood Science,  To know how to use Python to produce windows and colours along with specified co-ordinates Sunday, April 12, 2015.
Working with images and scenes CS 5010 Program Design Paradigms “Bootcamp” Lesson 2.5 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Python Programming, 2/e1 CS177: Programming in Multimedia Objects Recitation Topic: Graphics Library.
Part 3 Introduction to CSS. CSS Text Text Styles h1 {color: green} // rgb(0,255,0), #00ff00 h2{letter-spacing: 0.5cm} // 2px h3 {text-align: right} //
1 Python Programming: An Introduction to Computer Science Chapter 3 Objects and Graphics.
How to install the Zelle graphics package
Chapter 4 Objects and Graphics
Python: Graphics
Graphics. Graphics Features in Java Topics to be covered Topics to be covered Graphics Basics Graphics Basics Coordinate System Coordinate System Graphics,
Animation CSC 161: The Art of Programming Prof. Henry Kautz 10/14/2009.
CSC 110 Objects and Graphics [Reading: chapter 4] CSC 110 E 1.
Chapter 5 Graphics.  We’ve been doing command line programming, but now it’s time to try GUI programming—programming in a graphical user interface, using.
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
Slide 1 of 24 1) Launch Fireworks 2) Under File, choose New 3) In the New Document dialog box, enter Width: 100, Height 160, Resolution 72, and choose.
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.
Applets Applet is java program that can be embedded into HTML pages. Java applets runs on the java enabled web browsers such as mozilla and internet explorer.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 9 GUI Programming Using Tkinter 1.
Some Graphics CS303E: Elements of Computers and Programming.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Python Programming, 1/e1 Programming Thinking and Method (5a) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University.
CSC 1010 Programming for All Lecture 7 Input, Output & Graphics.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Xiaojuan Cai Computational Thinking 1 Lecture 5 Objects and Graphics Xiaojuan Cai (蔡小娟) Fall, 2015.
CPSC 217 T03 Week II Part #1: SimpleGraphics.py Hubert (Sathaporn) Hu.
LING 408/508: Programming for Linguists Lecture 23 November 25 th.
Interaction with Graphics Also displaying GIFs. Text Output on the graphics window There is a class called Text which will put the message on the graphics.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 4 Objects and Graphics.
10. MORE OBJECTS Rocky K. C. Chang October 18, 2015 (Based on from Charles Dierbach. Introduction to Computer Science Using Python and adapted from John.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 4 Objects and Graphics.
5. COMPUTING WITH GRAPHICS OBJECTS Dennis Y. W. Liu and Rocky K. C. Chang October 8, 2015 (Adapted from John Zelle’s slides)
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
© Anselm Spoerri Lecture 7 Meaning –Guiding Principles for Term Project Mechanics –Interactivity Recap –Simple and Disjointed Rollovers and Image Map –Navigation.
CS 115 Lecture 7 Graphics – coordinate systems, Text, Entry, aliases Taken from notes by Dr. Neil Moore.
Vahé Karamian Python Programming CS-110 CHAPTER 4 Objects and Graphics.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
CS 115 Lecture 6 Graphics Taken from notes by Dr. Neil Moore.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 4 Objects and Graphics Killer cars.
3. Drawing Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
ENGINEERING 1D04 Tutorial 4. What are we doing today? Focus Functions Scope of Variables Returning Values Objects Graphics library Aliasing Events Mouse.
Graphics Taken from notes by Dr. Neil Moore & Dr. Debby Keen
MS Paint A simple drawing tool that can be used to create simple or elaborate drawings. These drawings can be either black-and-white or color, and can.
Python Programming: An Introduction to Computer Science
Python Programming: An Introduction to Computer Science
9. Drawing.
Python Programming: An Introduction to Computer Science
Flash Interface, Commands and Functions
Example: Card Game Create a class called “Card”
Python: Simple Graphics and Event-driven Programming
9. Drawing Let's Learn Python and Pygame
Lesson One: The Beginning Chapter 1: Pixels Learning Processing Daniel Shiffman Presentation by Donald W. Smith Graphics from
Graphics Part I Taken from notes by Dr. Neil Moore
Chapter 5 Working with Images
GUI Using Python.
Graphics Part I Taken from notes by Dr. Neil Moore
CS 115 Lecture Graphics II – coordinate systems, Text, Entry, aliases
CS 106A, Lecture 12 More Graphics
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
CS 115 Lecture Graphics II – coordinate systems, Text, Entry, aliases
CSc 110, Spring 2018 Lecture 9: Parameters, Graphics and Random
SSEA Computer Science: Track A
Chapter 2 Graphics Programming with C++ and the Dark GDK Library
Graphics Part I Taken from notes by Dr. Neil Moore
Simple Graphics Package
Topics Graphical User Interfaces Using the tkinter Module
Class 6 using the math library
Working with images and scenes
MAINTAINING FILES AND CUSTOMIZING WINDOWS Section 2
Presentation transcript:

GUI in Python Ismail Abumuhfouz

Outlines Why GUI in CS 170 GUI in Python. Configure graphics library in python. Major Components of the library. Exercises.

Why GUI in CS170 Most students are visual learners. Approximately 65 percent of the population are visual learners. – Mind Tools, 1998. Visual aids in the classroom improve learning by up to 400 percent. – 3M Corporation, 2001. * Motivating beginners to learn programming using graphics (Students hate/bored/Don’t fully understand programs using shell). Help students understand the basic elements of the programming more (iterations, selections, functions, lists, files). Incorporate graphics into the class’s projects (the last 2 projects).

Graphics Libraries in Python Use the turtle library (for more details click here). Use the graphics library designed by Dr. John N Zelle. (for more details click here) Use Pygame Library (for more details click here). Use Tkinter. GUI frameworks (or toolkits) (for more details click here). Others (for 3D graphics use PyOpenGL and piglet, for Visual Python, use vpython, Others. ) I use the graphics library designed by Dr. John N Zelle in my intro to programming course for the following reasons. Simple. Fit more introductory programming courses.

Steps Need for Using Graphics Library First: Download the graphics library (graphics.py) from here. Second: Save the library inside: Windows: c:\Python34\Lib\site-packages Mac:: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site -packages Others: you can also save the library inside the same folder where you have source code file. Third: Review the following reference module for any help.

Major Components Window Class Other Class Point Shapes: Line Circle Rectangle Polygon Image Display Message (Prompt) Text Getting Input Data Entry

Program Skeleton # import the graphics library from graphics import * def main(): width =600 height=600 # Create the Window Object win = GraphWin (“ Title “ , width , height) # Change the window object’s properties # Create other objects needed for the program …… # close the window win.getMouse() win.close() main()

Window Class # Create a window object win = GraphWin (“ Title “ , windowWidth , windowHeight) windowWidth , windowHeight are measured in pixels # Major methods to change the window object’s properties .close() # Close the window .flush() # Updates drawing to graphics window .getHeight() # Gets the Height of the window .getWidth() # Gets the Width of the window .getMouse() # Wait for mouse click and return Point obj representing click location .setBackground(color) # Sets the background color of the window . setCoords(xll, yll, xur, yur) # Sets the coordinate system of the window so that the lower left corner is at (xll, yll) and the upper right corner is at (xur, yur)

Point Class # Create a Point object Point_Object = Point(x, y) # Main methods .getX() # the int value of the Point's x-coordinate .getY() # the int value of the Point's y-coordinate # Draw and Undraw object on/from graphic window .draw(graphwin) # Draw the object in graphwin, which should be a GraphWin object. A GraphicsObject may only be drawn into one window. .udraw() # Undraw the object (i.e. hide it).

Objects are drawn using Absolute position Coordinate Systems Cartesian coordinate system Computer coordinate system Objects are drawn using Absolute position

Other Classes (Line & Rectangle) # Create a Line object Line_Object = Line( Point1, Point2) # Main methods .getP1() # get one end-point Point object .getP2() # get get the other Point object .getCenter() # get a Point object corresponding to the Line's center .draw(graphwin) # Draw the object in graphwin .udraw() # Undraw the object (i.e. hide it). # Create a Rectangle object Rectangle_Object = Rectangle ( Point1, Point2) # Main methods .getP1() # get one end-point Point object .getP2() # get get the other Point object .getCenter() # get a Point object corresponding to the Line's center .draw(graphwin) # Draw the object in graphwin .udraw() # Undraw the object (i.e. hide it).

Other Classes (Circle & Oval) # Create a Line object Circle_Object = Circle ( Point1, radius ) # Main methods .getCenter() # get a Point object corresponding to the circle's center .getRadius() # returns the int value of the Circle's radius .draw(graphwin) # Draw the object in graphwin .udraw() # Undraw the object (i.e. hide it). # Create an Oval object Oval_Object = Oval ( Point1, Point2) # Main methods .getP1() # returns a clone of the corresponding corner of the .getP2() # oval's bounding box (opposite corners of bounding square) .getCenter() # get a Point object corresponding to the oval's center .draw(graphwin) # Draw the object in graphwin .udraw() # Undraw the object (i.e. hide it).

Other Classes (Polygon & Mouse) # Create a Polygon object Polygon_Object = Polygon ( List of Points ) # Main methods .getPoints() # returns a list of points in the polygon .draw(graphwin) # Draw the object in graphwin .udraw() # Undraw the object (i.e. hide it). # Mouse Click on the window object Point_Object= WindowObject.getMouse() # Wait for mouse click and return a Point object representing the click location.

Other Classes (Image) # Create an image object image_Object = Image( Point , “ Name and path of the image” ) # Supported Images. This library supports only PPM and GIF image # Main methods .getWidth() # returns the width of the image .getHeight() # returns the height of the image .draw(graphwin) # Draw the object in graphwin .udraw() # Undraw the object (i.e. hide it).

Other Class (Text) # Create a Text object Text_Object = Text ( Point, Message) Display a text message centered at the point. # Main methods .getText () # returns the message displayed .setText(text) # Change the message .setTextColor(color) #change the text color .setFace(family) # set font face, ex. "arial" "courier" .setSize(size) # set font size (5-36 are legal) .setStyle(style) # set font style ex. "bold" "italic" .draw(graphwin) # Draw the object in graphwin .udraw() # Undraw the object (i.e. hide it).

Other Class (Entry) # Create an Entry object Entry_Object = Entry ( Point, width ) Display a place for the user to type. # Main methods .getText () # returns the typed data entered by the user .setText(String text) # Change the message displayed inside the entry .setTextColor(color) #change the text color .setFace(family) # set font face, ex. "arial" "courier" .setSize(size) # set font size (5-36 are legal) .setStyle(style) # set font style ex. "bold" "italic" .draw(graphwin) # Draw the object in graphwin .udraw() # Undraw the object (i.e. hide it). # Note: Make sure to follow the creation of the entry object with getMouse method before extracting the text of the entry using .getText().

Common Methods to All Graphics Object Classes .draw(graphwin) # Draw the object in graphwin, which should be a GraphWin object. A GraphicsObject may only be drawn into one window. .udraw() # Undraw the object (i.e. hide it). .clone() # create a new polygon object that is an exact copy of this one .move(dx, dy) # move object dx units in x and dy units in y direction .setFill(color) # Set interior color to color .setOutline(color) # Set outline color to color .setWidth(width) # Set line weight to width

Color System Use a string that represents the color name. Can use different color depth 1-4 Example: “red” “black” “red1” “blue4” Use the function: color_rgb (redValue, GreenValue, blueValue) Where: redValue, GreenValue, blueValue take values from 0-255 Example: Black color= color_rgb ( 0, 0, 0) White color= color_rgb ( 255, 255, 255) Green color = color_rgb ( 0, 255, 0) Red color= color_rgb( 255, 0, 0) Using Color’s Name Using color_rgb function

Exercises # Exercise 1 Show the following texts on the screen. Using GUI in CS 170

Exercises # Exercise 2 Ask the user to click two points on the screen. Use these two points as center points for two circles with radius 10, then draw these circles on the screen. Draw a line between these two points, then find the distance between these two points –length of the line – using the following equation, then display it on the screen. Use the two points as corner points of a rectangle. Draw that rectangle on the screen and then display its area and perimeter . Solve each requirement above using a separate function.