Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.5 kB
1
Indexable
Never
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.gridlayout import GridLayout

def dodle():
    pass


class Btn(Button):
    def __init__(self, funks, **kwargs):
        super().__init__(**kwargs)
        self.funks = funks

        self.turnOn = False
        self.background_color = [1, 0, 0, 1]

    def on_press(self):
        for one_funk in self.funks:
            one_funk()
        self.switch()

    def switch(self):
        if self.turnOn:
            self.background_color = [1, 0, 0, 1]
        else:
            self.background_color = [0, 1, 0, 1]

        self.turnOn = not self.turnOn


class PuzzleScreen(Screen):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        gl = GridLayout(cols=1, spacing=8, padding=8)

        self.bt1 = Btn(text="1", funks=[])
        self.bt2 = Btn(text="2", funks=[])
        self.bt3 = Btn(text="3", funks=[])

        self.bt1.funks.append(self.bt2.switch)
        self.bt2.funks.append(self.bt3.switch)
        self.bt3.funks.append(self.bt1.switch)

        gl.add_widget(self.bt1)
        gl.add_widget(self.bt2)
        gl.add_widget(self.bt3)

        self.add_widget(gl)


class MyApp(App):
    def build(self):
        sm = ScreenManager()
        sm.add_widget(PuzzleScreen())
        return sm


MyApp().run()
Leave a Comment