How to reference objects in other screens using kivy screenmanager
By : Ola AlYamani
Date : March 29 2020, 07:55 AM
it should still fix some issue You are trying to access ids dictionary, that's nice, yet in a completely different instance, that's why this error: code :
AttributeError: 'super' object has no attribute '__getattr__'
self.manager.screens[1].sc1log.text = 'Coming from main'
# no ids, because you put it into a variable before
<MainScreen>:
id: scrmain
BoxLayout:
Label:
Label:
id: mainlog
Button:
Button:
{'mainlog': <WeakProxy to <kivy.uix.label.Label object at 0x12345678>>}
|
Kivy ScreenManager switch screens leaving buttons
By : Chantouch Sek
Date : March 29 2020, 07:55 AM
|
screenmanager kivy define callback function to switch screens
By : gogo_yubari
Date : March 29 2020, 07:55 AM
To fix this issue Replace ScreenManager().current = "SettingsScreen" with sm.current = "settings" Rename class name from mainwidget to MainWidget ( CapWords convention) Example main.py code :
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.core.window import Window
from kivy.lang import Builder
Builder.load_string("""
#:kivy 1.11.0
<MenuScreen>:
MainWidget:
<SettingsScreen>:
BoxLayout:
Button:
text: 'My settings button'
Button:
text: 'Back to menu'
on_press: root.manager.current = 'settings'
""")
class MainWidget(Widget):
def __init__(self, **kwargs):
super(MainWidget, self).__init__(**kwargs)
print("\nmainwidget:")
btnnext = Button(text='go to next', pos=(200, 400))
btnnext.bind(on_press=self.gonext)
self.add_widget(btnnext)
# def savecard(self, btn_instance):
def gonext(self ,btn_inst):
sm.current = "settings"
class MenuScreen(Screen):
pass
class SettingsScreen(Screen):
pass
class ScreenManager(ScreenManager):
pass
# Create the screen manager
sm = ScreenManager()
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(SettingsScreen(name='settings'))
class TestApp(App):
def build(self):
Window.clearcolor = (0,0,0.3,1)
return sm
if __name__ == '__main__':
TestApp().run()
|
Kivy: How do I use layouts within seperate screens while using ScreenManager?
By : user2623146
Date : March 29 2020, 07:55 AM
I wish this helpful for you Your code is working OK. The image is at the top-right corner. Your problem is the size of that Image widget. Its as big as the size of the window. code :
Image:
size_hint: .1, .1
source: 'settings-cog.png'
|
Kivy ScreenManager does not switch screens (pure python)
By : Debendia Oli
Date : March 29 2020, 07:55 AM
around this issue What you must manipulate is screen_manager.current and not screen_manager.current_screen. You must also refer to the screen by its name. code :
IMAGE_SIZE = (640, 480)
class MainScreen(Screen):
def __init__(self, path, **kwargs):
super(MainScreen, self).__init__(**kwargs)
Window.size = (IMAGE_SIZE[0], IMAGE_SIZE[1])
with self.canvas:
self.bg = Image(source=path)
self.bind(pos=self.update_bg)
self.bind(size=self.update_bg)
self._keyboard = Window.request_keyboard(self._keyboard_closed, self, 'text')
self._keyboard.bind(on_key_down=self._on_keyboard_down)
def update_bg(self, *args):
self.bg.pos = self.pos
self.bg.size = self.size
def _keyboard_closed(self):
print('My keyboard have been closed!')
self._keyboard.unbind(on_key_down=self._on_keyboard_down)
self._keyboard = None
def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
if keycode[1] == 'escape':
keyboard.release()
if keycode[1] == 'enter':
print('before enter', screen_manager.current)
screen_manager.transition.direction = 'left'
screen_manager.current = "1"
print('after enter', screen_manager.current)
return True
screen_manager = None
scree_1 = MainScreen(path_1, name="1")
scree_2 = MainScreen(path_2, name="2")
class MyApp(App):
def build(self):
global screen_manager
screen_manager = ScreenManager()
screen_manager.add_widget(scree_2)
screen_manager.add_widget(scree_1)
return screen_manager
if __name__ == '__main__':
MyApp().run()
|