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 311: 9.33

Answer

code

Work Step by Step

# 9.33 (Draw an arrow line) Write a program that randomly draws an arrow line when # the Draw a Random Arrow Line button is clicked, as shown in Figure 9.40b. import random from tkinter import * class MainGUI: def __init__(self): window = Tk() self.canvas = Canvas(window, width=300, height=300, bg="white") self.canvas.pack() btn = Button(window, text="Draw a random arrow line", command=self.draw) btn.pack() window.mainloop() def draw(self): self.canvas.delete("line") x1 = random.randint(5, 290) y1 = random.randint(5, 290) x2 = random.randint(5, 290) y2 = random.randint(5, 290) self.canvas.create_line(x1, y1, x2, y2, arrow=LAST, tags="line") 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.