diff --git a/first_screen.kv b/first_screen.kv index 3c17584fc0306513d730e640e6193d126c2c9b74..08e2856432e9ff2bedf50f872ac722bcc5e88f4c 100644 --- a/first_screen.kv +++ b/first_screen.kv @@ -5,7 +5,7 @@ text: 'This is the first screen.' Button: text: 'This button prints a number.' - on_press: root.print_number() + on_press: root.print_number() # In a custom widget's Kv, `root` refers to the custom widget. Button: text: 'Change…' - on_press: app.open_second_screen() + on_press: app.open_second_screen() # But `app` still refers to the application object. diff --git a/first_screen.py b/first_screen.py index 4178e4a2c0d644fa691401e2c66ef924c91b32ee..8037d7bec672f3fee69671b75e615e33a63efa8c 100644 --- a/first_screen.py +++ b/first_screen.py @@ -3,7 +3,7 @@ from kivy.uix.screenmanager import Screen from kivy.properties import NumericProperty -Builder.load_file('first_screen.kv') +Builder.load_file('first_screen.kv') # Because this is not the main app Kv, we must load it explicitly. class FirstScreen(Screen): diff --git a/main.py b/main.py index 58f773d3abb094e7877bd8b077b5a7b26586be27..b7ebfae295827a9e71c546219312c35ee687c1f5 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,10 @@ from kivy.app import App +# The following lines ensure that FirstScreen and SecondScreen are available for when the Kv code is loaded. + +# Because neither PyCharm nor PyLint are aware of the associated Kv, we must disable their warnings about these widgets +# not being used. + # noinspection PyUnresolvedReferences from first_screen import FirstScreen # pylint: disable=unused-import # noinspection PyUnresolvedReferences diff --git a/second_screen.kv b/second_screen.kv index 00d033ccb603b7495bd51f628cfe8c049cc5ddd1..7fcb6f5f3e0a1b55c067f7a6f5f2f229b0b8f8d8 100644 --- a/second_screen.kv +++ b/second_screen.kv @@ -4,7 +4,7 @@ Label: text: 'This is the second screen.' Label: - text: root.message + text: root.message # In a custom widget's Kv, `root` refers to the custom widget. Button: text: 'Change…' - on_press: app.open_first_screen() + on_press: app.open_first_screen() # But `app` still refers to the application object. diff --git a/second_screen.py b/second_screen.py index aa3db0bad3a31a2bf3b6eed1f71eadf971628f60..a51690311c0d66498e07f6ef7f2b08a0889e80ab 100644 --- a/second_screen.py +++ b/second_screen.py @@ -3,8 +3,8 @@ from kivy.uix.screenmanager import Screen from kivy.properties import StringProperty -Builder.load_file('second_screen.kv') +Builder.load_file('second_screen.kv') # Because this is not the main app Kv, we must load it explicitly. class SecondScreen(Screen): - message = StringProperty('Hello, World!') + message = StringProperty('Hello, World!') # This property is changed by twoscreen.kv. diff --git a/twoscreen.kv b/twoscreen.kv index 2b4c9654e499415fe9e1a724cc25632c9fbc50a5..ca47926547a9d440a91391d2925718b50e06e4fc 100644 --- a/twoscreen.kv +++ b/twoscreen.kv @@ -5,4 +5,4 @@ ScreenManager: SecondScreen: id: second name: 'second' - message: 'This is a message!' + message: 'This is a message!' # The app sends information to the custom widgets by setting their properties.