简体   繁体   中英

"Cannot create a consistent method resolution order (MRO) for bases Widget, Screen" when using ScreenManager in kivy

My code consists of 2 pages that each one has only a button by pressing which it's supposed to it to show the other page:

class Paging(ScreenManager):
    def __init__(self, **kwargs):
        super(Paging, self).__init__(**kwargs)
        self.sm = ScreenManager(transition=RiseInTransition())
        self.sm.add_widget(Test1(name='screen_one'))
        self.sm.add_widget(Test2(name='screen_two'))

class Test1(Widget, Screen):
    def __init__(self, **kwargs):
        super(Test1, self).__init__(**kwargs)
        btn1 = Button(text='page1', font_size="15sp",
        btn1.bind(on_press = self.callback)
        self.add_widget(btn1)

    def callback(self):
        print("Button is pressed")
        self.manager.transition.direction = 'left'
        self.manager.transition.duration = 1
        self.manager.current = 'screen_two'

class Test2(Widget, Screen):
    def __init__(self, **kwargs):
        super(Test1, self).__init__(**kwargs)
        btn1 = Button(text='page1', font_size="15sp",
        btn1.bind(on_press = self.callback)
        self.add_widget(btn1)

    def callback(self):
        print("Button is pressed")
        self.manager.transition.direction = 'left'
        self.manager.transition.duration = 1
        self.manager.current = 'screen_one'

but every time I run it, it shows this error:

Cannot create a consistent method resolution order (MRO) for bases Widget, Screen

I guess it's about the order of parent classes; however, switching places didn't help either.

Your code:

class Test1(Widget, Screen):

is trying to extend both Widget and Screen , but Screen is a Widget , so you don't need Widget . Try changing the above code to:

class Test1(Screen):

and similar for Test2 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM