Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 11 - Multidimensional Lists - Programming Exercises - Page 396: 11.44

Answer

code

Work Step by Step

# 11.44 (Tkinter: draw a polygon) Write a program that prompts the user to enter the # coordinates of six points and fills the polygon that connects the points, as # shown in Figure 11.16a. Note that you can draw a polygon using # canvas.create_polygon(points), where points is a two-dimensional list that # stores the x- and y-coordinates of the points. from tkinter import * # Import tkinter class MainGUI: def __init__(self): coordinates = input("Enter coordinates for six points separated by spaces: ") c = coordinates.split() points = [[eval(c[i]), eval(c[i + 1])] for i in range(0, len(c), 2)] window = Tk() # Create a window window.title("Polygon") # Set title width = 400 height = 250 canvas = Canvas(window, width=width, height=height) canvas.pack() canvas.create_polygon(points) window.mainloop() # Create an event loop MainGUI()
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.