Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-Kivy覆盖方法_Python_Kivy_Overriding - Fatal编程技术网

Python-Kivy覆盖方法

Python-Kivy覆盖方法,python,kivy,overriding,Python,Kivy,Overriding,我已经尽可能地减少了这个例子,但它似乎是空的,而且之后的问题也不完全一样 我想我误解了类变量和实例变量,但Kivy在这方面没有帮助我:我们创建了很多类,但从未实例化它们 当然,我希望出现“Screenx实例已覆盖问题”消息,我只看到“未覆盖” 日历工 from kivy.properties import StringProperty from kivy.app import App from kivy.lang import Builder from kivy.uix.screenmanage

我已经尽可能地减少了这个例子,但它似乎是空的,而且之后的问题也不完全一样

我想我误解了类变量和实例变量,但Kivy在这方面没有帮助我:我们创建了很多类,但从未实例化它们

当然,我希望出现“Screenx实例已覆盖问题”消息,我只看到“未覆盖”

日历工

from kivy.properties import StringProperty
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.clock import Clock

class Menu(Screen):
    pass

class CalculGenerique(Screen):
    question = StringProperty()

    def __init__(self, **kwargs):
        super(CalculGenerique, self).__init__(**kwargs)
        Clock.schedule_once(self.late_init, 0)

    def late_init(self, *largs):
        self.renew_question()

    def renew_question(self):
        self.question = "Not overwritten"

class Screen1(CalculGenerique):
    def renew_question(self):
        self.question = "Screen1 instance has overwritten question"

class Screen2(CalculGenerique):
    def renew_question(self):
        self.question = "Screen2 instance has overwritten question"

class MyScreenManager(ScreenManager):
    pass

class CalendarApp(App):

    def build(self):
        root_widget = Builder.load_file("calendrier.kv")
        return root_widget

if __name__ == "__main__":
    app = CalendarApp()
    app.run()

千伏日历

#:import App kivy.app.App

MyScreenManager:
    Menu:
    CalculGenerique:
        name: 'Screen1'
    CalculGenerique:
        name: 'Screen2'

<Menu>:
    name: 'Menu'
    BoxLayout:
        orientation: 'vertical'

        Button:
            text: 'Screen1'
            on_press : app.root.current = 'Screen1'

        Button:
            text: 'Screen2'
            on_press : app.root.current = 'Screen2'

        Button:
            text: 'Quitter l app'
            on_press : App.get_running_app().stop()

<CalculGenerique@Screen>:
    BoxLayout:
        orientation: 'vertical'
        Button:
            text: 'Back to Menu'
            on_press : app.root.current = 'Menu'
        Label:
            text: root.question
#:导入应用程序kivy.App.App
MyScreenManager:
菜单:
计算总则:
名称:“屏幕1”
计算总则:
名称:“屏幕2”
:
名称:“菜单”
盒子布局:
方向:“垂直”
按钮:
文本:“屏幕1”
按:app.root.current='Screen1'
按钮:
文本:“屏幕2”
按:app.root.current='Screen2'
按钮:
文本:“退出者l应用程序”
按下:App.get_running_App().stop()按钮
:
盒子布局:
方向:“垂直”
按钮:
文本:“返回菜单”
按:app.root.current='菜单'
标签:
文本:root.question
您的“千伏”规则:

MyScreenManager:
    Menu:
    CalculGenerique:
        name: 'Screen1'
    CalculGenerique:
        name: 'Screen2'
创建两个
CalculGenerique
类的实例,但不创建
Screen1
Screen2
的实例。我认为您只需要将该规则更改为:

MyScreenManager:
    Menu:
    Screen1:
        name: 'Screen1'
    Screen2:
        name: 'Screen2'
屏幕
名称
属性仅用于标识
屏幕
,而不指定类