Я пытался исправить эту ошибку, которая выдает мне, когда я пытаюсь добавить виджет в класс, который наследует Gridlayout, я действительно не знаю, является ли класс, который наследует виджет, проблемой, или я имею в виду gridlayout, япытался сделать много вещей без какого-либо результата, поэтому я хочу спросить, есть ли у этого решение
первый класс это класс, который наследует виджет
class MyPaintElement(Widget):
def __init__(self, **kwargs):
super(MyPaintElement, self).__init__(**kwargs)
self.active = False
def on_touch_down(self, touch):
# Check if touch event is inside widget
if self.collide_point(touch.x, touch.y):
self._draw_rectange()
def on_touch_move(self, touch):
# Check if touch event is inside widget
if self.collide_point(touch.x, touch.y):
# If so, draw rectangle
self._draw_rectange()
def _draw_rectange(self):
self.canvas.clear()
with self.canvas:
# lets draw a semi-transparent red square
Color(1, 1, 1, 1, mode='rgba')
Rectangle(pos=self.pos, size=(self.width*0.9, self.height*0.9))
self.active = True
def clear(self, color):
self.canvas.clear()
with self.canvas:
if color == "black":
# lets draw a semi-transparent red square
Color(0, 0.65, 0.65, 1, mode='rgba')
else:
Color(0, 0.2, 0.2, 1, mode='rgba')
Rectangle(pos=self.pos, size=(self.width*0.9, self.height*0.9))
self.active = False
def mark(self):
self._draw_rectange()
второй класс, где явызовите этот экземпляр в части "add_widget", который наследует GridLayout
class MyPaintWidget(GridLayout):
CODING_SIZE = 4
def __init__(self, size, **kwargs):
super(MyPaintWidget, self).__init__(**kwargs)
self.cols = size
for index in range(self.cols * self.cols):
self.add_widget(MyPaintElement())
def clear(self):
index = 0
#with self.canvas.before:
# Color(0, .1, .3, 1) # green; colors range from 0-1 instead of 0-255
# self.rect = Rectangle(size=self.size,
# pos=self.pos)
for child in self.children:
if index % 2:
child.clear("dark-turquoise")
else:
child.clear("black")
index += 1
def get_pattern(self):
# Initial pattern is an empty list of integers
pattern = []
# Integer representation or first row of pattern (bottom)
val = 0
# Counter to obtain integer value from binary row
count = 1
# For each MyPaintElement instance, verify if active and
# add integer value to val depending on its position (count)
for child in self.children:
if child.active:
val += count
count *= 2
# If row over, append to pattern array and
# start encoding new one
if count == pow(2, MyPaintWidget.CODING_SIZE):
pattern.append(val)
val = 0
count = 1
return pattern
def draw_pattern(self, pattern):
""" Draw given pattern in painter"""
for index in range(len(pattern)):
# Get children in groups of four (As codification was made by groups of four)
child_offset = index*MyPaintWidget.CODING_SIZE
child_set = self.children[child_offset:child_offset+MyPaintWidget.CODING_SIZE]
# Convert current number of pattern into binary
format_str = "{0:0"+str(MyPaintWidget.CODING_SIZE)+"b}"
bin_pattern_element = format_str.format(pattern[index])
# Traverse binary, mark or clear corresponding child
for j in range(len(bin_pattern_element)):
if bin_pattern_element[MyPaintWidget.CODING_SIZE-1-j] == "1":
child_set[j].mark()
else:
if j % 2:
child_set[j].clear("dark-turquoise")
else:
child_set[j].clear("black")
, и, наконец, ошибка, которую он мне дает, это
File ".\main.py", line 513, in <module>
MyPaintApp().run()
File "C:\PATH\site-packages\kivy\app.py", line 829, in run
root = self.build()
File ".\main.py", line 509, in build
intentions_ui = IntentionsInterface()
File ".\main.py", line 244, in __init__
self.add_widgets_layouts()
File ".\main.py", line 364, in add_widgets_layouts
self.desired_state_panel = GridLayout(cols=1, padding_x = 10, size_hint_y = 1,size_hint_x=0.5)
File "C:\PATH\site-packages\kivy\uix\gridlayout.py", line 256, in __init__
super(GridLayout, self).__init__(**kwargs)
File "C:\PATH\site-packages\kivy\uix\layout.py", line 76, in __init__
super(Layout, self).__init__(**kwargs)
File "C:\PATH\site-packages\kivy\uix\widget.py", line 350, in __init__
super(Widget, self).__init__(**kwargs)
File "kivy\_event.pyx", line 243, in kivy._event.EventDispatcher.__init__
TypeError: object.__init__() takes exactly one argument (the instance to initialize)
, поэтому я хочучтобы знать, почему это происходит, я был бы очень признателен за любой совет или рекомендацию!