I am trying to create a two screen Kivy touchscreen interface on a Raspberry Pi that acts like a selectable Menu interface to do a function depending on the Selection.
Screen 1:
Shows Eight Blocks - each block is made up by a BoxLayout that consists of Label, Image, Timer, Button.
Screen 2:
A pre defined list of blocks with names and pictures and a timer value.
Now lets say I want block 2 on screen one to have its values set to whatever I select on Screen2, I would like to press on the Button of Block2 on screen 1, it opens screen2 and I select one of the items. Now depending on what I selected on screen2, it should now load the values of that item and update block 2 on screen1 with Label, Image, Timer. The Timer should be a countdown timer.
I have the basic Layout that works showing screen1 and screen2 but am batteling with the value update concept and the multiple Blocks. The Code is still a bit of a mess but hope it gives an idea of what I am trying to do - will past it after posting the question. Screen Two still has no values..
main.py
# class for aqua.kv file
class MainScreen(Screen):
pass
# class for screen.kv file
class SelectScreen(Screen):
pass
class Tray1(Screen):
pass
# class for date.kv file
class Date(BoxLayout,EventDispatcher):
def __init__(self,**kwargs):
super(Date,self).__init__(**kwargs)
Builder.load_file('date.kv')
Builder.load_file('tray1.kv')
class MyApp(App):
time = StringProperty()
def update(self,*args):
self.time = str(time.asctime())
def build(self):
Clock.schedule_interval(self.update,1)
# Set up the layout:
return Builder.load_file('screen.kv')
if __name__ == '__main__':
MyApp().run()
screen.kv
ScreenManager:
id: screen_manager
MainScreen:
id: main_screen
name: 'MainScreen'
manager: 'screen_manager'
SelectScreen:
id: select_screen
name: 'SelectScreen'
manager: 'screen_manager'
# on_release: background_color = 1,0,0,1
<MainScreen>:
BoxLayout:
canvas.before:
Color:
rgba: .5,.6,.7,1
Rectangle:
pos: self.pos
size: self.size
orientation:'vertical'
BoxLayout:
size_hint:1,.2
Date:
BoxLayout:
orientation: 'horizontal'
# size_hint: .2,1
BoxLayout:
orientation: 'vertical'
Label:
id:btn_tray1
font_size: 30
Image:
source:"logo.png"
Tray1:
Button:
id:btn_tray1_1
font_size: 30
text:"Tray1"
on_release: app.root.current = "SelectScreen"
#on_release: app.root.current = "SelectScreen"
# on_release: btn_tray1.background_color = 1,0,0,1
Button:
id:btn_tray2
font_size: 30
text:"Tray2"
on_release: app.root.current = "SelectScreen"
Button:
id: btn_tray3
font_size: 30
text:"Tray3"
on_release: app.root.current = "SelectScreen"
<SelectScreen>:
BoxLayout:
canvas.before:
Color:
rgba: .5,.6,.7,1
Rectangle:
pos: self.pos
size: self.size
orientation:'vertical'
BoxLayout:
orientation: 'horizontal'
BoxLayout:
orientation: 'horizontal'
# size_hint: .2,1
Button:
size_hint:1,.2
id:btn_tray5
font_size: 30
text:"Tray5"
on_release: app.root.current = "MainScreen"
# on_release: btn_tray1.background_color = 1,0,0,1
Button:
size_hint:1,.2
id:btn_tray6
font_size: 30
text:"Tray6"
on_release: app.root.current = "MainScreen"
Button:
size_hint:1,.2
id: btn_tray7
font_size: 30
text:"Tray7"
on_release: app.root.current = "MainScreen"
# on_release: btn_tray3.background_color = 1,0,0,1
Button:
size_hint:1,.2
id: btn_tray8
font_size: 30
text:"Tray8"
on_release: app.root.current = "MainScreen"
# on_release: btn_tray4.background_color = 1,0,0,1
Related
I'm a new coder and I have so many things I don't understand. I'm making a book management GUI, buy and sell books.
main.py
from kivy.app import App
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.uix.widget import Widget
#Define our different screens
class FirstWindow(Screen):
pass
class SecondWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
kv = Builder.load_file('images.kv')
class MyLayout(Widget):
pass
class QuanlyApp(App):
def build(self):
return kv
if __name__=='__main__':
QuanlyApp().run()
images.kv
WindowManager:
FirstWindow:
SecondWindow:
<FirstWindow>:
name: "first"
BoxLayout:
Button:
text: "enter"
font_size: 32
size: 100, 50
pos: root.x, root.top - 50
on_release:
app.root.current = "second"
root.manager.transition.direction = "left"
Button:
text: "import"
font_size: 32
size: 100, 50
pos: root.x - 50, root.top
on_release:
app.root.current = "second"
root.manager.transition.direction = "left"
<SecondWindow>:
name: "second"
BoxLayout:
orientation: "vertical"
size: root.width, root.height
Label:
text: "hi"
font_size: 24
GridLayout:
cols: 2
rows: 7
Label:
text: "Ten sach"
id: name
color: '6EE369'
TextInput:
id: name
multiline: False
Label:
text: "Tac gia"
color: '6EE369'
TextInput:
id: author
multiline: False
Label:
text: "The loai"
color: '6EE369'
TextInput:
id: kind
multiline: False
Label:
text: "Ma"
color: '6EE369'
TextInput:
id: id
multiline: False
Label:
text: "Gia nhap"
color: '6EE369'
TextInput:
id: price1
multiline: False
Label:
text: "Gia xuat"
color: '6EE369'
TextInput:
id: price2
multiline: False
Button:
text: "buy"
font_size: 24
size: 100, 50
background_color: 'E36982'
background_normal: ''
Button:
text: "sell"
font_size: 24
size: 100, 50
background_color: '82E369'
background_normal: ''
The result I want is:
enter image description here
and
enter image description here
I can print value from images.kv but I can't find how to print the values of two TextInputs when a button is pressed.
This is the first time I have posted so I have a lot of mistakes. Thanks if I can get any help from everyone.
On the first screen, I have a checkbox that asks the user if they want their image in landscape mode. On the second screen, my code currently uses a canvas and rotates the image 90 degrees. If that box is not checked, that means the user wants the image to be portrait mode, and I need that canvas to be cleared.
my.kv
WindowManager:
MainWindow:
SecondWindow:
<MainWindow>:
id: main_window
name: "main"
BoxLayout:
orientation: "vertical"
size: root.width, root.height
padding: 50
Label:
text: "Email"
color: 0,0,0,1
font_size: 32
BoxLayout:
orientation: "horizontal"
Label:
text: "Email Address:"
color: 0,0,0,1
TextInput:
size_hint_y: None
pos_hint: {'center_y': .5}
height: 38
multiline: True
padding: 10
BoxLayout:
orientation: "horizontal"
Label:
text: "Display Landscape Mode?"
color: 0,0,0,1
CheckBox:
id: checkbox_confirm_mode
on_active:
root.checkbox_click_mode(self, self.active)
pos_hint: {'center_x': .5}
BoxLayout:
orientation: "horizontal"
Label:
text: "Stretch image to fill screen?"
color: 0,0,0,1
CheckBox:
id: checkbox_confirm_stretch
on_active:
root.checkbox_click_stretch(self, self.active)
pos_hint: {'center_x': .5}
BoxLayout:
orientation: "horizontal"
Label:
text: "I double-checked that my email is typed correctly:"
color: 0,0,0,1
CheckBox:
id: checkbox_confirm_email
on_active:
root.checkbox_click(self, self.active)
root.disable_button()
pos_hint: {'center_x': .5}
BoxLayout
orientation: "vertical"
Button:
id:submit_button
text: "Submit"
disabled: True
size_hint: (0.2, None)
pos_hint: {'center_x': .5}
height: 50
on_release:
app.root.current = "second"
root.manager.transition.direction = "left"
<SecondWindow>:
id: second_window
name: "second"
canvas:
Rotate:
angle: 90
origin: self.center
Image:
source: 'Troy.png'
keep_ratio: True
allow_stretch: False
main.py
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.core.window import Window
from kivy.properties import ObjectProperty
from kivy.config import Config
Config.set('input', 'mouse', 'mouse,multitouch_on_demand')
class MainWindow(Screen):
def on_pre_enter(self):
Window.size = (750,400)
Window.clearcolor = (1, 1, 1, 1)
def checkbox_click(self, instance, value):
return value
def checkbox_click_mode(self, instance, value):
return value
def checkbox_click_stretch(self, instance, value):
return value
def clear_canvas(self):
self.canvas.clear()
return
def disable_button(self):
if self.ids.checkbox_confirm_email.active == False:
self.ids.submit_button.disabled = True
else:
self.ids.submit_button.disabled = False
class SecondWindow(Screen):
def on_pre_enter(self):
Window.size = (500,500)
Window.clearcolor = (0,0,0,0)
pass
class WindowManager(ScreenManager):
pass
class MyMainApp(App):
def build(self):
return kv
kv = Builder.load_file("my.kv")
if __name__ == "__main__":
MyMainApp().run()
For your current design you can control it from outside as,
First set properties in SecondWindow for setting the angle, stretch instruction etc. and then control them depending on the state of those (weak reference of the check boxes) checkbox_confirm_mode etc. from the MainWindow as,
class SecondWindow(Screen):
angle = NumericProperty(0)
allow_strech = BooleanProperty(False)
def on_pre_enter(self):
screen = self.manager.get_screen("main")
angle_value = screen.ids.checkbox_confirm_mode.active
stretch_value = screen.ids.checkbox_confirm_stretch.active
self.angle = 90*angle_value # Less calculation.
self.allow_strech = stretch_value # Less calculation.
Window.size = (500,500)
...
Now in the kvlang of SecondWindow,
<SecondWindow>:
id: second_window
name: "second"
canvas:
Rotate:
angle: root.angle
origin: self.center
Image:
source: 'Troy.png'
keep_ratio: True
allow_stretch: root.allow_strech
I am trying to type in text from one screen. Press a button and move to another screen and have that text be shown in a label. I've seen a few questions that are similar to mine, but have not been able to figure out how to use the posted solutions and have been stuck for hours (Link One, Link Two, Link Three). I believe that I need to use the __init__ method somewhere because this is an instance? I tried using the first link, but the label ends up blank (the code does run). Any Advice?
main.py
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.app import App
from kivy.lang.builder import Builder
class SecondWindow(Screen):
def get_unique_text(self):
x = self.manager.get_screen("first")
y = x.ids.unique.text
return str(y)
class FirstWindow(Screen):
pass
class MainWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
kv_main = Builder.load_file('main.kv')
class MyApp(App):
def build(self):
return kv_main
if __name__ == '__main__':
MyApp().run()
main.kv
#:include First.kv
#:include Second.kv
WindowManager:
MainWindow:
FirstWindow:
SecondWindow:
<MainWindow>
name: "main"
BoxLayout:
Button:
text: "Press"
on_release:
app.root.current = "first"
First.kv
<FirstWindow#Screen>:
name: "first"
BoxLayout:
orientation: "vertical"
Label:
text: "Enter Unique Text for Saving"
font_size: 20
text_size: self.width, None
halign: 'center'
TextInput:
id: unique
hint_text: 'example: Stand25'
Button:
text: "Press"
on_release:
app.root.current = "second"
Second.kv
<SecondWindow#Screen>:
name: "second"
BoxLayout:
orientation: "vertical"
Label:
text: "Unique Text"
font_size: 20
text_size: self.width, None
halign: 'center'
Label:
text: root.get_unique_text()
font_size: 16
canvas.before:
Color:
rgba: 1,1,1,1
Rectangle:
pos: self.pos
size: self.size
color: 0,0,0,1
Button:
text: "Go Back"
on_release:
app.root.current = "first"
Another approach is to use the on_enter() method of a Screen in order to fetch the text. This also requires an id for the unique Label:
<SecondWindow#Screen>:
name: "second"
BoxLayout:
orientation: "vertical"
Label:
text: "Unique Text"
font_size: 20
text_size: self.width, None
halign: 'center'
Label:
id: unique # added id
# text: root.get_unique_text()
font_size: 16
canvas.before:
Color:
rgba: 1,1,1,1
Rectangle:
pos: self.pos
size: self.size
color: 0,0,0,1
Button:
text: "Go Back"
on_release:
app.root.current = "first"
Just add an on_enter() method to the SecondWindow class:
class SecondWindow(Screen):
def on_enter(self, *args):
self.ids.unique.text = self.get_unique_text()
def get_unique_text(self):
x = self.manager.get_screen("first")
y = x.ids.unique.text
return str(y)
In your Second.kv you can reference the text of the TextInput in the First.kv by making a couple changes to the kv files. First, in the main.kv, add an id for the FirstWindow (and eliminate the SecondWindow for now):
WindowManager:
MainWindow:
FirstWindow:
id: first # added id
# SecondWindow: # this gets added later
<MainWindow>
name: "main"
BoxLayout:
Button:
text: "Press"
on_release:
app.root.current = "first"
Then, in the Second.kv, set up the reference to the text of the TextInput:
<SecondWindow#Screen>:
name: "second"
BoxLayout:
orientation: "vertical"
Label:
text: "Unique Text"
font_size: 20
text_size: self.width, None
halign: 'center'
Label:
text: app.root.ids.first.ids.unique.text # reference to unique text
font_size: 16
canvas.before:
Color:
rgba: 1,1,1,1
Rectangle:
pos: self.pos
size: self.size
color: 0,0,0,1
Button:
text: "Go Back"
on_release:
app.root.current = "first"
Since the kv for SecondWindow uses app.root, it will cause an error if SecondWindow is instantiated before the root widget of the App is assigned. To avoid that, add the SecondWindow after a slight delay:
class MyApp(App):
def build(self):
Clock.schedule_once(self.add_second_screen)
return kv_main
def add_second_screen(self, dt):
self.root.add_widget(SecondWindow())
The screen has multiple layouts all child of a box layout. I am trying to add a button in the last sub layout (grid-layout) when a button in other layout is clicked. The code does not crash but nothing happens too. I want to add buttons to the layout with id drinkslayout when a button is clicked eg pepsi,sprite
Python:
class MainScreen(Screen):
pass
class AnotherScreen(Screen):
pass
class ScreenManagement(ScreenManager):
pass
class Stacks(StackLayout):
pass
present=Builder.load_file('hellokivy2.kv') #Specifying location of kv file
class MainApp(App):
def build(self):
return present
def drinksSelect(self,value): #creating a button by referring the id of the layout in which to create button
print(value)
yolo = AnotherScreen()
yolo2 = yolo.ids.newButtonLayout
button = Button(text="value",size_hint= (0.2,0.4))
yolo2.add_widget(button)
if __name__ == "__main__":
MainApp().run()
KV
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
ScreenManagement:
transition: FadeTransition()
MainScreen:
AnotherScreen:
<MainScreen>:
name: "main"
canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
orientation: 'vertical'
size:root.size
Button:
text: "Slideshow"
GridLayout:
cols: 2
Button:
text: "Burger"
Button:
text: "Drinks"
on_release: app.root.current = "other"
Button:
text: "Fries"
Button:
text: "Others"
Label:
text: "Your Cart"
font_size: 40
color:(0,0,0,1)
size_hint_y: None
canvas.before:
Color:
rgba:150,10,200,0.5
Rectangle:
pos: self.pos
size: self.size
<AnotherScreen>:
name: "other"
canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
size:root.size
orientation: 'vertical'
GridLayout:
size_hint_y:0.1
orientation: 'vertical'
rows: 1
Button:
color: 1,1,1,1
font_size: 25
size_hint_y:0.1
text: "Back Home"
on_release: app.root.current = "main"
Label:
text: "Project BAM"
canvas.before:
Color:
rgba: 0,0,0,1
Rectangle:
pos: self.pos
size: self.size
Button:
color: 1,1,1,1
font_size: 25
size_hint_y:0.1
text: "Profile"
on_release: app.root.current = "main"
Button:
color: 1,1,1,1
font_size: 25
size_hint_y:0.9
text: "Whats New"
on_release: app.root.current = "main"
GridLayout:
rows: 2
Button:
text: "Pepsi"
on_release: app.drinksSelect(1)
Button:
text: "7up"
on_release: app.drinksSelect(2)
Button:
text: "Fanta"
on_release: app.drinksSelect(3)
Button:
text: "Mountain Dew"
on_release: app.drinksSelect(4)
Button:
text: "Diet Pepsi"
on_release: app.drinksSelect(5)
Button:
text: "Sprite"
on_release: app.drinksSelect(6)
GridLayout:
id: drinksLayout
size_hint_y: 0.3
orientation: 'horizontal'
rows: 1
Button:
id: label1
size_hint: 0.2,0.4
background_normal:'1.jpg'
text: 'B1'
Button:
id: label2
size_hint: 0.2,0.4
background_normal:'1.jpg'
text: 'B1'
Button:
id: label3
size_hint: 0.2,0.4
background_normal:'1.jpg'
text: 'B1'
Ok the problem was your drinksSelect method, also you need to keep the value of your screens
Try this:
py:
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang.builder import Builder
from kivy.uix.stacklayout import StackLayout
from kivy.uix.button import Button
from kivy.properties import ObjectProperty
class MainScreen(Screen):
pass
class AnotherScreen(Screen):
dl = ObjectProperty()
l = 0
limit = 3 # Fix your limit here 3 is an example
class ScreenManagement(ScreenManager):
m_s = ObjectProperty() # Here I will keep the value of the MainScreen
a_s = ObjectProperty() # Here the AnotherScreen so I can use them later
class Stacks(StackLayout):
pass
present = Builder.load_file('hellokivy2.kv') # Specifying location of kv file
class MainApp(App):
def build(self):
return present
def drinksSelect(self,value): # creating a button by referring the id of the layout in which to create button
print(value)
if self.root.a_s.l < self.root.a_s.limit: # You know what I mean
button = Button(text=str(value), size_hint= (0.2,0.4))
self.root.a_s.ids['place_remaining'].add_widget(button)
self.root.a_s.l += 1
if __name__ == "__main__":
MainApp().run()
kv:
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
ScreenManagement:
m_s: m_s # so I can use it in the .py file
a_s:a_s # same here
transition: FadeTransition()
MainScreen:
id: m_s
AnotherScreen:
id: a_s
<MainScreen>:
name: "main"
canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
orientation: 'vertical'
size:root.size
Button:
text: "Slideshow"
GridLayout:
cols: 2
Button:
text: "Burger"
Button:
text: "Drinks"
on_release: app.root.current = "other"
Button:
text: "Fries"
Button:
text: "Others"
Label:
text: "Your Cart"
font_size: 40
color:(0,0,0,1)
size_hint_y: None
canvas.before:
Color:
rgba:150,10,200,0.5
Rectangle:
pos: self.pos
size: self.size
<AnotherScreen>:
name: "other"
dl : drinksLayout
canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
size:root.size
orientation: 'vertical'
GridLayout:
size_hint_y:0.1
orientation: 'vertical'
rows: 1
Button:
color: 1,1,1,1
font_size: 25
size_hint_y:0.1
text: "Back Home"
on_release: app.root.current = "main"
Label:
text: "Project BAM"
canvas.before:
Color:
rgba: 0,0,0,1
Rectangle:
pos: self.pos
size: self.size
Button:
color: 1,1,1,1
font_size: 25
size_hint_y:0.1
text: "Profile"
on_release: app.root.current = "main"
Button:
color: 1,1,1,1
font_size: 25
size_hint_y:0.9
text: "Whats New"
on_release: app.root.current = "main"
GridLayout:
rows: 2
Button:
text: "Pepsi"
on_release: app.drinksSelect(1)
Button:
text: "7up"
on_release: app.drinksSelect(2)
Button:
text: "Fanta"
on_release: app.drinksSelect(3)
Button:
text: "Mountain Dew"
on_release: app.drinksSelect(4)
Button:
text: "Diet Pepsi"
on_release: app.drinksSelect(5)
Button:
text: "Sprite"
on_release: app.drinksSelect(6)
GridLayout:
id: drinksLayout
size_hint_y: 0.3
orientation: 'horizontal'
rows: 1
GridLayout:
id: place_remaining
rows: 1
size_hint_x: 80
Button:
id: label1
width: 40 # Set the size_hint_x to None and then set the width if you want a fixed dimension
size_hint: None,0.4
background_normal:'1.jpg'
text: 'B1'
Button:
id: label2
width: 40
size_hint: None,0.4
background_normal:'1.jpg'
text: 'B1'
Button:
id: label3
width: 40
size_hint: None,0.4
background_normal:'1.jpg'
text: 'B1'
Outputs:
I hope that the code is a bit clear now
All my program works up-to a point and I'm road blocked by it.
My program loads some starter screens in the main app.
Based on user input the program loads a completely different sub app.
Problem occurs when trying to change screens in the loaded sub app
Here is the code where the problem exists:
The .py file:
import kivy
kivy.require('1.10.0')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen, ScreenManager, FadeTransition
from kivy.uix.button import Button
from kivy.uix.label import Label
chClass = ""
class ScreenManage(ScreenManager):
pass
class Home(ScreenManager):
pass
class TitleScreen(Screen):
pass
class GameScreen(Screen):
pass
class ClassScreen(Screen):
pass
class Warrior1(Screen):
def GetChClass(self, ch):
return ch
def build(self):
ExecuteW().run()
class Acrobat1(Screen):
def GetChClass(self, ch):
return ch
class Spell1(Screen):
def GetChClass(self, ch):
return ch
class HomeScreen(Screen):
pass
class WarriorStats(Screen):
pass
class AcrobatStats(Screen):
pass
class SpellCasterStats(Screen):
pass
class ExecuteW(App):
def build(self):
return Home()
class RevengeApp(App):
def build(self):
return ScreenManage()
if __name__ == '__main__':
print chClass
RevengeApp().run()
revenge.kv:
#: import sm kivy.uix.screenmanager
#: import Factory kivy.factory.Factory
#: import builder kivy.lang.Builder
<ScreenManage>
transition: sm.FadeTransition()
TitleScreen:
ClassScreen:
GameScreen:
Warrior1:
Acrobat1:
Spell1:
WarriorStats:
<TitleScreen>
on_touch_down: app.root.current = 'Game'
canvas:
Rectangle:
size: self.size
pos: self.pos
source: 'KnightArmor.jpg'
BoxLayout:
orientation: 'vertical'
Label:
font_size: '30sp'
color: 1,0,0,1
text: "Warrior's Revenge"
Label:
color: 1,0,0,1
text: "Click to Continue:"
<GameScreen>
name: 'Game'
canvas:
Rectangle:
size: self.size
pos: self.pos
source: 'KnightArmor.jpg'
BoxLayout:
Button:
size_hint: .5,.1
text: "New Game"
on_release: app.root.current = 'Class'
Button:
size_hint: .5,.1
text: "Load Game"
<ClassScreen>
name: 'Class'
BoxLayout:
orientation: 'vertical'
Label:
text: "Choose Your Path"
Button:
text: "Warrior"
on_release: app.root.current = "Warrior1"
Button:
text: "Acrobat"
on_release: app.root.current = "Acrobat1"
Button:
text: "Spell Caster"
on_release: app.root.current = "Spell1"
<Warrior1>
name: "Warrior1"
canvas:
Rectangle:
size: self.size
pos: self.pos
source: "Warrior.jpg"
BoxLayout:
orientation: 'vertical'
Label:
font_size: "20sp"
text: "Warrior's are physically strong"
color: 0,.5,1,1
Label:
font_size: "20sp"
text: "experts in hand to hand combat,"
color: 0,.5,1,1
Label:
font_size: "20sp"
text: "and knowledgeable in the ways of"
color: 0,.5,1,1
Label:
font_size: "20sp"
text: "arms and armor"
color: 0,.5,1,1
BoxLayout:
orientation: 'horizontal'
Button:
text: "Cancel"
on_release: app.root.current = "Class"
Button:
name: "warrior_confirm"
text: "Confirm"
on_release: chClass = root.GetChClass('Warrior')
on_release: root.build()
executew.kv:
#: import sm kivy.uix.screenmanager
<Home>:
transition: sm.FadeTransition()
HomeScreen:
WarriorStats:
<HomeScreen>
name: 'Home'
AnchorLayout:
Button:
text: "Stats"
on_release: app.root.current = 'WStats'
<WarriorStats>
name: 'WStats'
canvas:
Rectangle:
size: self.size
pos: self.pos
source: "Warrior.jpg"
The problem:
When clicking the stats button on the home screen in executew the WarriorStats screen named 'WStats' should be loaded, but I get the error "no screen with name 'WStats'"
Answer that I figured out on my own
class HomeScreen(Screen):
def switch(self):
self.manager.current = "WStats"
And in executew:
<HomeScreen>
Button:
text: "Stats"
on_release: root.switch()