I'm making a calendar app in for mobile in kivy and wantto make a scrollview for a stack layout but keep getting this error and I don't know why
python code
`
from kivymd.app import MDApp
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.stacklayout import StackLayout
from calendar import monthrange
import calendar
year = 2022
month_int = 11
num_days = monthrange(year, month_int)[1]
weekheader = str(calendar.weekheader(3))
days = weekheader.split(" ")
days_length = len(days)
month = calendar.monthcalendar(year, month_int)
print(month)
start_day = month[0].count(0)
print(start_day)
class GridLayoutExample(GridLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
for l in range(2):
label4 = Label()
self.add_widget(label4)
button2 = Button(text=str(month_int))
self.add_widget(button2)
button3 = Button(text=str(year))
self.add_widget(button3)
for k in range(3):
label3 = Label()
self.add_widget(label3)
for j in range(days_length):
label1 = Label(text=days[j], color=(0, 0, 0, 1))
self.add_widget(label1)
for g in range(start_day):
label2 = Label()
self.add_widget(label2)
for i in range(num_days):
button = Button(text=str(i 1))
button.my_id = str(i 1) "-" str(month_int) "-" str(year)
self.ids[str(i 1) "-" str(month_int) "-" str(year)] = button
self.add_widget(button)
class LayoutExample(StackLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
for l in range(10):
label4 = Label(text="zeer plezant \n \n \n ha \n haha", size = self.size, color=(0, 0, 0, 1), size_hint=(None, None))
self.add_widget(label4)
button = Button(text="verwijder")
self.add_widget(button)
button = Button(text="wijzig")
self.add_widget(button)
class agenda1(MDApp):
pass
agenda1().run()
`
kv file
#:kivy 1.0
PageLayoutExample:
<PageLayoutExample@PageLayout>:
GridLayoutExample:
ScrollViewExample:
<ScrollViewExample@ScrollView>:
LayoutExample:
<GridLayoutExample>:
#left-right top-bottom
cols: 7
orientation: "lr-tb"
size: root.minimum_width, root.minimum_height
padding: ("20dp", "20dp", "20dp", "20dp")
<LayoutExample>:
cols: 1
orientation: "lr-tb"
padding: ("20dp", "20dp", "20dp", "20dp")
size_hint: 1, None
height: self.minimum_height
Did I do something wrong in my code?
I want the scrollview to scroll as far as it has to to get all the data on the screen but not go any farther than that. because I iterate over an x amount task I don't really see a way to get less iterations in
CodePudding user response:
Because you are using height: self.minimum_height
in your LayoutExample
, you must provide definite sizes for its children.
The Buttons
that you add to LayoutExample
have the default size_hint
of (1,1)
, so that causes an infinite loop in the LayoutExample
layout calculations. It is trying to calculate its minimum_height
, so each Button
height gets set to the LayoutExample
height, the LayoutExample
then calculates and applies a new minimum height that will hold the Buttons
. The Buttons
then change their size to the new size of the LayoutExample
, which triggers a new calculation by LayoutExample
of its minimum_height
....
The fix is just to specify a size
for each Button
, something like:
for l in range(10):
label4 = Label(text="zeer plezant \n \n \n ha \n haha", size=self.size, color=(0, 0, 0, 1),
size_hint=(None, None))
self.add_widget(label4)
button = Button(text="verwijder", size_hint=(None, None), size=(100, 20))
self.add_widget(button)
button = Button(text="wijzig", size_hint=(None, None), size=(100, 20))
self.add_widget(button)