a)  The red ball moves clockwise while the blue ball moves counter clockwise b)  The red ball moves 2 times as faster as the blue ball moves c)  At the center of the frame, the coordinates of the balls are shown in real time.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
  1. a)  The red ball moves clockwise while the blue ball moves counter clockwise

  2. b)  The red ball moves 2 times as faster as the blue ball moves

  3. c)  At the center of the frame, the coordinates of the balls are shown in real time.

"An example of drawing and animation on a Canvas object"""
from tkinter import *
import time
tk = Tk()
Height
= 300
Width = 400
tk.title('COMP3140-01 tkinter Demo')
canvas = Canvas (tk, width=Width, height= Height)
canvas.pack()
ball=canvas.create_oval(e,100,50,50, fill='red')
delta_x = 5
delta_y=0
var = StringVar()
coord = Label(canvas, textvariable=var, fg='red')
labelfont = ('times', 20, 'bold')
coord.config(font=labelfont)
canvas.create_window(180, 180, window=coord) #Add the coordinate label to the
canvas
while True:
canvas.move(ball, delta_x, delta_y) #draw and move the ball object
pos=canvas.coords (ball)
#records the coordinates
# Move the ball
if pos[2] > Width:
delta_x=-5
elif pos[0]<=8 :
delta_x=5
var.set('( %d, %d ) '%(pos[0], pos[1]))
#update the coordinates
tk.update()
#update the whole frame
time.sleep(0.03)
Transcribed Image Text:"An example of drawing and animation on a Canvas object""" from tkinter import * import time tk = Tk() Height = 300 Width = 400 tk.title('COMP3140-01 tkinter Demo') canvas = Canvas (tk, width=Width, height= Height) canvas.pack() ball=canvas.create_oval(e,100,50,50, fill='red') delta_x = 5 delta_y=0 var = StringVar() coord = Label(canvas, textvariable=var, fg='red') labelfont = ('times', 20, 'bold') coord.config(font=labelfont) canvas.create_window(180, 180, window=coord) #Add the coordinate label to the canvas while True: canvas.move(ball, delta_x, delta_y) #draw and move the ball object pos=canvas.coords (ball) #records the coordinates # Move the ball if pos[2] > Width: delta_x=-5 elif pos[0]<=8 : delta_x=5 var.set('( %d, %d ) '%(pos[0], pos[1])) #update the coordinates tk.update() #update the whole frame time.sleep(0.03)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education