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 397: 11.46

Answer

code

Work Step by Step

# 11.46 (Tkinter: display a STOP sign) Write a program that displays a STOP sign, as # shown in Figure 11.17a. The hexagon is in red and the text is in black. from tkinter import * # Import tkinter import math class MainGUI: def __init__(self): window = Tk() # Create a window window.title("Stop Sign") # Set title width = 200 height = 150 canvas = Canvas(window, bg="white", width=width, height=height) canvas.pack() xCenter = width / 2 yCenter = height / 2 radius = min(width, height) * 0.5 # Create a Polygon object polygon = [] # Add points to the polygon for i in range(8): polygon.append([xCenter + radius * math.cos(i * 2 * math.pi / 8 + 2 * math.pi / 16), yCenter - radius * math.sin(i * 2 * math.pi / 8 + 2 * math.pi / 16)]) # Draw the polygon canvas.create_polygon(polygon, fill="red") canvas.create_text(xCenter, yCenter, text="STOP", font="Times 30 bold", fill="white") 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.