Pregunta

I have been struggling recently creating a filled Circle in Kivy that stays a circle when the window is re-sized to a different width or height. I looked at the question here:

Centering an object in Kivy

But when I implement my Circle like so:

<BigCircle>
    width: min(self.size)
    height: min(self.size)
    pos_hint: {'center_x': .5, 'center_y': .5}
    canvas:
        Color:
            rgb: 1, 1, 0
        Ellipse:
            size: self.size
            pos: self.pos

<MainScreen>:
    FloatLayout
        size: root.size
        canvas:
            Color:
                rgb: 1, 1, 1
            Rectangle:
                size: self.size

        BigCircle:
            id: big_cir

class MainScreen(Screen):
    pass
class MyApp(App):
    def build(self):
        sm = ScreenManager(transition=NoTransition())
        sm.add_widget(MainScreen(name="Main"))
        return sm

I get the error:

[Critical][Clock ]Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute

I am doing nothing with the Clock, but I am using a ScreenManager. Currently, MainScreen is the only screen. If I change the height/width to not include the min() then it works, but that is necessary to keep the Circle circular. Otherwise it becomes elongated when re-sized and looks bad.

¿Fue útil?

Solución

The problem is you have an infinite loop due to BigCircle width and height being adjusted based on its size (width, height). Try changing your BigCircle to:

<BigCircle>
    canvas:
        Color:
            rgb: 1, 1, 0
        Ellipse:
            size: min(self.size), min(self.size)
            pos: root.center_x - min(self.size)/2, root.center_y - min(self.size)/2
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top