pip install kivy
import random
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.graphics import Color, Ellipse
from kivy.clock import Clock
from kivy.core.window import Window
class CatchTheBallApp(App):
pass
CatchTheBallApp().run()
class Car:
speed = 100
car = Car()
print(car.speed)
import random
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.graphics import Color, Ellipse
from kivy.clock import Clock
from kivy.core.window import Window
class Ball(Widget):
def __init__(self):
super(Ball, self).__init__()
self.size = (50, 50)
self.pos = (random.randint(50, Window.width - 50), random.randint(50, Window.height - 50))
with self.canvas:
Color(random.random(), random.random(), random.random(), 1)
Ellipse(pos=self.pos, size=self.size)
class CatchTheBallApp(App):
pass
CatchTheBallApp().run()
import random
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.graphics import Color, Ellipse
from kivy.clock import Clock
from kivy.core.window import Window
class Ball(Widget):
def __init__(self):
super(Ball, self).__init__()
self.size = (50, 50)
self.pos = (random.randint(50, Window.width - 50), random.randint(50, Window.height - 50))
with self.canvas:
Color(random.random(), random.random(), random.random(), 1)
Ellipse(pos=self.pos, size=self.size)
class CatchTheBallGame(Widget):
def __init__(self):
super(CatchTheBallGame, self).__init__()
self.score = 0
self.score_label = Label(text=f"Очки: {self.score}", pos_hint={'center_x': 0.1, 'center_y': 0.95})
self.add_widget(self.score_label)
self.ball = Ball()
self.add_widget(self.ball)
class CatchTheBallApp(App):
def build(self):
game = CatchTheBallGame()
return game
CatchTheBallApp().run()
import random
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.graphics import Color, Ellipse
from kivy.clock import Clock
from kivy.core.window import Window
class Ball(Widget):
def __init__(self):
super(Ball, self).__init__()
self.size = (50, 50)
self.pos = (random.randint(50, Window.width - 50), random.randint(50, Window.height - 50))
with self.canvas:
Color(random.random(), random.random(), random.random(), 1)
Ellipse(pos=self.pos, size=self.size)
def move(self):
self.pos = (random.randint(50, Window.width - 50), random.randint(50, Window.height - 50))
self.canvas.clear()
with self.canvas:
Color(random.random(), random.random(), random.random(), 1)
Ellipse(pos=self.pos, size=self.size)
class CatchTheBallGame(Widget):
def __init__(self):
super(CatchTheBallGame, self).__init__()
self.score = 0
self.score_label = Label(text=f"Очки: {self.score}", pos_hint={'center_x': 0.1, 'center_y': 0.95})
self.add_widget(self.score_label)
self.ball = Ball()
self.add_widget(self.ball)
self.event = Clock.schedule_interval(self.update, 1)
def update(self, dt):
self.ball.move()
class CatchTheBallApp(App):
def build(self):
game = CatchTheBallGame()
return game
CatchTheBallApp().run()
import random
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.graphics import Color, Ellipse
from kivy.clock import Clock
from kivy.core.window import Window
class Ball(Widget):
def __init__(self):
super(Ball, self).__init__()
self.size = (50, 50)
self.pos = (random.randint(50, Window.width - 50), random.randint(50, Window.height - 50))
with self.canvas:
Color(random.random(), random.random(), random.random(), 1)
Ellipse(pos=self.pos, size=self.size)
def move(self):
self.pos = (random.randint(50, Window.width - 50), random.randint(50, Window.height - 50))
self.canvas.clear()
with self.canvas:
Color(random.random(), random.random(), random.random(), 1)
Ellipse(pos=self.pos, size=self.size)
class CatchTheBallGame(Widget):
def __init__(self):
super(CatchTheBallGame, self).__init__()
self.score = 0
self.score_label = Label(text=f"Очки: {self.score}", pos_hint={'center_x': 0.1, 'center_y': 0.95})
self.add_widget(self.score_label)
self.ball = Ball()
self.add_widget(self.ball)
self.event = Clock.schedule_interval(self.update, 1)
def update(self, dt):
self.ball.move()
def on_touch_down(self, touch):
if self.ball.collide_point(*touch.pos):
self.score += 1
self.score_label.text = f"Очки: {self.score}"
self.ball.move()
self.event.cancel()
self.event = Clock.schedule_interval(self.update, 1)
class CatchTheBallApp(App):
def build(self):
game = CatchTheBallGame()
return game
CatchTheBallApp().run()