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 305: 9.8

Answer

code

Work Step by Step

# 9.8 (Display numbers in a triangular pattern) Write a program that displays numbers # in a triangular pattern, as shown in Figure 9.25d. The number of lines in the display # changes to fit the window as the window resizes. from tkinter import * window = Tk() width = 300 height = 300 canvas = Canvas(window, bg="white", width=width, height=height) canvas.pack() for i in range(1, 12): s = "" for j in range(1, i + 1): s += str(j) + " " canvas.create_text(width / 2, i * height / 12, text=s, fill="red") window.mainloop() # Create an event loop
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.