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 309: 9.24

Answer

code

Work Step by Step

# 9.24 (Display circles) Write a program that displays a new larger circle with a left # mouse click and removes the largest circle with a right mouse click, as shown in # Figure 9.35. from tkinter import * # Import tkinter width = 200 height = 200 class MainGUI: def __init__(self): window = Tk() # Create a window window.title("Dynamic Circles") # Set title self.radius = 20 self.tagNumber = 0 self.canvas = Canvas(window, bg="white", width=width, height=height) self.canvas.create_oval(width / 2 - self.radius, height / 2 - self.radius, width / 2 + self.radius, height / 2 + self.radius, tags=str(self.tagNumber)) self.canvas.pack() self.canvas.bind("", self.addACircle) self.canvas.bind("", self.removeACircle) window.mainloop() # Create an event loop def addACircle(self, event): self.tagNumber += 1 self.radius += 5 self.canvas.create_oval(width / 2 - self.radius, height / 2 - self.radius, width / 2 + self.radius, height / 2 + self.radius, tags=str(self.tagNumber)) def removeACircle(self, event): self.canvas.delete(str(self.tagNumber)) self.radius -= 5 self.tagNumber -= 1 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.