from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
import random

from kivy.config import Config

Config.set('graphics', 'resizable', True)


class TileStack(GridLayout):  # use a layout to hold the buttons

    TARGET = 0
    N_ROWS = 10
    N_COLS = 15

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        TARGET = random.randint(0, 9) + random.randint(0, 9)
        print(TARGET)
        for i in range(0, self.N_ROWS):
            for j in range(0, self.N_COLS):
                rand_int1 = random.randint(100, 254) / 255
                rand_int2 = random.randint(100, 254) / 255
                rand_int3 = random.randint(100, 254) / 255
                rand_int4 = random.randint(0, 9)
                my_color = (rand_int1, rand_int2, rand_int3, 1)
                my_id = str(i) + '-' + str(j) + '-' + str(rand_int4)
                self.add_widget(Tile(my_id, my_color, rand_int4))


class Tile(Button):  # a Tile is a Button

    def __init__(self, my_id, my_color, my_value, **kwargs):
        super().__init__(**kwargs)
        self.text = str(my_value)
        self.font_size = 32
        self.bold = True
        self.color = (0, 0, 0, 1)
        self.background_normal = ""
        self.background_color = my_color
        self.tile_id = my_id
        self.bind(on_press=self.selected)

    def selected(self, obj):
        print(f"selected {self.tile_id}")


class Main(GridLayout):
    pass


class MainApp(App):
    pass


MainApp().run()
