Introduction to Programming using Python 1st Edition

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

Chapter 9 - GUI Programming using Tkinter - Programming Exercises - Page 310: 9.30

Answer

code

Work Step by Step

# 9.30 (Display a rectanguloid) Write a program that displays a rectanguloid, as shown # in Figure 9.39a. from tkinter import * # Import tkinter class MainGUI: def __init__(self): window = Tk() # Create a window window.title("Rectanguloid") # Set title width = 200 height = 150 canvas = Canvas(window, bg="white", width=width, height=height) canvas.pack() width = width * 0.9 - 30 height = height * 0.9 - 60 diff = min(width, height) * 0.4 # Draw the front rect canvas.create_rectangle(10, 60, 10 + width, 60 + height) # Draw the back rect canvas.create_rectangle(30, 60 - diff, 30 + width, 60 - diff + height) # Connect the corners canvas.create_line(10, 60, 30, 60 - diff) canvas.create_line(10, 60 + height, 30, 60 - diff + height) canvas.create_line(10 + width, 60, 30 + width, 60 - diff) canvas.create_line(10 + width, 60 + height, 30 + width, 60 - diff + height) 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.