

setText ( 'Click anywhere to quit' ) # change text message win. setWidth ( 4 ) # width of boundary line triangle. draw ( win ) vertices = # Use Polygon object to draw the triangle triangle = Polygon ( vertices ) triangle. draw ( win ) # Get and draw three vertices of triangle p1 = win. getWidth () / 2, 30 ), 'Click on three points' ) message. setBackground ( 'yellow' ) message = Text ( Point ( win. ''' from graphics import * def main (): win = GraphWin ( 'Draw a Triangle', 350, 350 ) win. '''Program: triangle.py or triangle.pyw (best name for Windows) Interactive graphics program to draw a triangle, with prompts in a Text object and feedback via mouse clicks. Window and click with the mouse as requested.Īfter you have run the program, you can examine the program in Idle While running the program, follow the prompts in the graphics Or on a Mac, you can run it using the Python Launcher, rather than Idle. You may be able to double click on the icon for triangle.py to run it. Return to the directory window for the Python examples. The Points where the user clicked the mouse.
Dont sleep gfx code#
Rather than the code specifying literal coordinates for all In addition it explicitly interacts with the user. The next example, triangle.py, illustrates similar starting andĮnding code. Location of the center of each balloon, so a loop over a list of Note that the steps for theĬreation of all three balloons are identical, except for the Is to make the Shell window be the current window and select from the menuĪnother simple drawing example is balloons.py. Because such a sequence is so common, I haveĪdded another method for Zelle’s GraphWin objects, promptClose,Īnd the program bombs out while there is a GraphWin on the screen,Ī dead GraphWin lingers. We will generally want to prompt the user to finally close the Terminated after the last line finishes executing, that is not trueįor programs that create new windows: The graphics window must beĮxplicitly closed. While our earlier text-based Python programs have automatically This mouse click will be used.) As you have seen before, Position of the mouse click is not important. Using win.getWidth()/2 means the horizontal position is set up to beĬentered, half way across the window’s width.Īfter the first two lines draw the prompting text, the line The new addition to the Text parameters here is win.getWidth() getWidth () / 2, 20 ), 'Click anywhere to quit.' ) message.

Modern screen usually have more than 1000 A pixel is the smallest little square that can byĭisplayed on your screen. Our graphics window object.) A small window, 200 by 200 pixels isĬreated. The assignment statement remembers the window object as Graphics package that automatically displays a window when it isĬreated. A GraphWin is a type of object from Zelle’s To the top, and preferably drag it around to make it visible beside There should be a new window labeled “Graphics Window”, created Look around on your screen, and possibly underneath other windows: Zelle’s module accessible, as if they were already defined like The first line above makes all the types of object of For the Python interpreter to find Zelle’s module, it Zelle’s graphics are not a part of the standard Pythonĭistribution.
