LAB 8 4МСО МартиновІван

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Лабораторна №8

Виконати вправу 12 с. 70-71 з підручника «Інформатика» підручник для 7 класу (авт.


Бондаренко О. О., Ластовецький В. В., Пилипчук О. П., Шестопалов Є. А.) – 2020 рік.

Підготував: Мартинов Іван 4МСО.


Код:
from tkinter import*

from random import*

from time import*

class Ball:

def __init__(self, canvas, x, y, color):

self.canvas = canvas

self.id = canvas.create_oval(x, y, x+50, y+50, fill=color)

self.dy = 2

def ruh(self):

pos = canvas.coords(self.id)

if pos[1] > 348 or pos[1] < 2:

self.dy = -1 * self.dy

canvas.move(self.id, 0, self.dy)

tk = Tk()

tk.title("Переміщення кульок") #вікно програми

canvas = Canvas(tk, width=500, height=400) #розмір полотна 500*400

canvas.pack()

list_ball = []

colors = ['red', 'orange', 'yellow', 'green', 'blue']

for i in range(10):

x = randint(10, 400)

y = randint(10, 350)

list_ball.append(Ball(canvas, x, y, colors[i % 5]))

def play():

for i in range(len(list_ball)):

list_ball[i].ruh()

tk.update() # Оновлення полотна


tk.after(10, play) # Затримка виконання програми

play()

tk.mainloop()

You might also like