How do I solve this code in Python kivy

Asked

Viewed 396 times

1

I’m trying to program a calendar using Python and the module kivy, but I have a problem that I don’t understand how I can solve:
This is the calendar.py file:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import ScreenManager, Screen
import calendar
from datetime import datetime

now = datetime.now()
cal = calendar.Calendar()

class Gerenciador(ScreenManager):
    pass

class Tarefas(Screen):
    def __init__(self,**kwargs):
        super().__init__(**kwargs)
        for dia in cal.itermonthdays(now.year, now.month):
            self.ids.box.add_widget(Tarefa(text=str(dia)))

class Tarefa(BoxLayout):
    def __init__(self,text='',**kwargs):
        super().__init__(**kwargs)
        self.ids.label.text = text

class Window(App):
    def build(self):
        return Gerenciador()

Window().run()

This is Window.KV:

<Gerenciador>:
    Tarefas:

<Tarefas>:
    BoxLayout:
        orientation:'vertical'
        ScrollView:
            BoxLayout:
                id:box
                orientation:'vertical'
                size_hint_y:None
                height:self.minimum_height

<Tarefa>:
    size_hint_y:None
    height:200
    Label:
        id:label
        font_size:30

When running, it results in error:

'super' Object has no attribute 'getattr'

Pointing to the line: self.ids.box.add_widget(Tarefa(text=str(dia))).

2 answers

0

Hello, looking at your go for each day of the month I got several zeros, I did not test running on the kivy, but try this way to observe if the error persists. Abs

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import ScreenManager, Screen
import calendar
from datetime import datetime

now = datetime.now()
cal = calendar.Calendar()

class Gerenciador(ScreenManager):
    pass

class Tarefas(Screen):
    def __init__(self,**kwargs):
        super().__init__(**kwargs)
        dias = [str(dia) for dia in cal.itermonthdays(now.year, now.month) if dia]
        for dia in dias:
            self.ids.box.add_widget(Tarefa(text=dia))

class Tarefa(BoxLayout):
    def __init__(self,text=False,**kwargs):
        super().__init__(**kwargs)
        if text:
            self.ids.label.text = text

class Window(App):
    def build(self):
        return Gerenciador()

Window().run()

-1

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView
import calendar
from datetime import datetime


now = datetime.now()
cal = calendar.Calendar()


class Tarefas(ScrollView):
    def __init__(self,tarefas,**kwargs):
        super().__init__(**kwargs)

        dias = [str(dia) for dia in cal.itermonthdays(now.year, now.month) if dia]
        for dia in dias:
            self.ids.box.add_widget(Tarefa(text=dia))
            
            
class Tarefa(BoxLayout):
    def __init__(self,text=False,**kwargs):
        super().__init__(**kwargs)
        if text:
            self.ids.label.text = text         

class Window(App):
    def build(self):
        return Tarefas([])
Window().run()

    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.