I have created a ScrollView with a GridLayout that has a bunch of buttons. my issue is that I cant get the buttons to be a perfect square when changing the window size.
.py file:
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty
from kivy.uix.scrollview import ScrollView
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.stacklayout import StackLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
class LogInScreen(Screen):
pass
class EmployeeScreen(Screen):
pass
class MyLayout(GridLayout):
def __init__(self,**kwargs):
super(MyLayout,self).__init__(**kwargs)
self.size_hint_y = (None)
self.bind(minimum_height = self.setter('height'))
class Manager(ScreenManager):
login_screen = ObjectProperty(None)
employee_screen = ObjectProperty(None)
class CptApp(App):
icon = 'Images\login\cptlogo.png'
title = 'CPT'
def build(self):
return Manager()
if __name__=='__main__':
CptApp().run()
enter code here
.kv file:
#: import Window kivy.core.window.Window
<Manager>:
id: screen_manager
login_screen: login_screen
employee_screen: employee_screen
LogInScreen:
id: login_screen
name: 'login'
manager: screen_manager
FloatLayout:
StackLayout:
orientation: 'lr-tb'
canvas:
Color:
rgba: 1,1,1,1
Rectangle:
pos: self.pos
size: self.size
Image:
size_hint_y: .1
source: 'Images\login\cptbanner.jpg'
allow_stretch: True
keep_ratio: True
Image:
source: 'Images\login\HD7Brw.jpg'
allow_stretch: True
keep_ratio: False
Label:
size_hint_y: .05
size_hint_x: .5
pos_hint: {"x": .25, "y": .7}
markup: True
text: '[i][b][color=#000000]USER NAME[/color][/b][/i]'
TextInput:
id: 'username_input'
multiline: False
size_hint_x: .4
size_hint_y: .05
pos_hint: {"x": .3, "y": .65}
Label:
size_hint_y: .05
size_hint_x: .5
markup: True
text: '[i][b][color=#000000]PASSWORD[/color][/b][/i]'
pos_hint: {'x': .25, 'y': .5}
TextInput:
id: 'password_input'
multiline: False
password: True
size_hint_x: .4
size_hint_y: .05
pos_hint: {'x': .3, 'y': .45}
Image:
source: 'Images/login/loginbutton.png'
size_hint_x: .25
size_hint_y: .1
pos_hint: {'x': .375, 'y': .25}
Button:
id: 'login_button'
background_color: 0,0,0,0
markup: True
text: '[i][b][color=#000000]LOGIN[/color][/b][/i]'
size_hint_x: .25
size_hint_y: .1
pos_hint: {'x': .375, 'y': .25}
on_release: screen_manager.current = 'employeescreen'
EmployeeScreen:
id: employee_screen
name: 'employeescreen'
manager: screen_manager
StackLayout:
orientation: 'lr-tb'
canvas:
Color:
rgba: 1,1,1,1
Rectangle:
pos: self.pos
size: self.size
Image:
size_hint_y: .1
source: 'Images\login\cptbanner.jpg'
allow_stretch: True
keep_ratio: True
ScrollView:
size: (Window.width, Window.height)
MyLayout:
cols: 2
height: self.minimum_height
pos: root.pos
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
height: 40
size_hint_y: None
text: 'TEST'
enter code here
I want the height of the buttons to be the same as whatever the width is.
You can simply set the width to the same constant like so:
Button:
height: 40
size_hint_y: None
width: 40
size_hint_x: None
text: 'TEST'
This produces perfect squares, but I guess this isn't what you want.
Another very simple thing is to set the button's height to be the same as it's width (literally):
Button:
size_hint_y: None
height: self.width
text: 'TEST'
Which produces a nice result.
.
And, when resized:
Perfect squares still.
Related
from kivy.lang import Builder
from kivymd.app import MDApp
KV = '''
MDScreen:
MDLabel:
id: lab
text: "WELLCOME"
bold:'True'
font_size: 40
halign: 'center'
color:1,0,1,1
pos_hint: {'center_x': .5, 'center_y': .83}
MDFillRoundFlatButton:
text: "language-python"
pos_hint: {"center_x": .5, "center_y": .5}
size_hint: (0.25,0.08)
on_release: app.kav()
'''
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
return Builder.load_string(KV)
def kav(self):
self.root.ids.lab.text = 'Have A Great Day'
Example().run()
i even tried this little app. it still doesnt work.???
It`s work
from kivy.lang import Builder
from kivymd.app import MDApp
KV = '''
MDScreen:
MDLabel:
id: lab
text: "WELLCOME"
bold:'True'
font_size: 40
halign: 'center'
color:1,0,1,1
pos_hint: {'center_x': .5, 'center_y': .83}
MDFillRoundFlatButton:
text: "language-python"
pos_hint: {"center_x": .5, "center_y": .5}
size_hint: (0.25,0.08)
on_release: app.kav()
'''
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
return Builder.load_string(KV)
def kav(self):
self.root.ids.lab.text = 'Have A Great Day'
Example().run()
So i am trying to add a MDFloatingActionButtonSpeedDial button into my screen but it just does not shows up but if i remove the MDNavigationRail part, it shows up fine.
Here's my code:
main.py
from kivymd.app import MDApp
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.uix.datatables import MDDataTable
from kivy.metrics import dp
class CfgScreen(Screen):
data = {
"Add user": "account-plus-outline",
"Edit user": "account-edit-outline",
"Delete user":"account-remove-outline"
}
my_label = "Wazap!"
rdata = [("a","b","c","d","e"),("a","b","c","d","e"),("a","b","c","d","e")]
def __init__(self, **kwargs):
super(CfgScreen, self).__init__(**kwargs)
def on_pre_enter(self):
self.create_ua_table()
def create_ua_table(self):
table_ua = MDDataTable(
column_data=[
("Username", dp(50)),
("Password", dp(100)),
("Level", dp(40)),
("Email", dp(70)),
("Company", dp(50))
],
row_data=self.rdata,
sorted_on="Username",
sorted_order="ASC",
elevation=2
)
self.ids.screen_cfg_user_account.add_widget(table_ua)
class MainApp(MDApp):
def build(self):
self.title = "Banana BMS"
self.theme_cls.primary_palette = "Teal"
self.theme_cls.primary_hue = "500"
sm = ScreenManager()
sm.add_widget(CfgScreen(name="cfg"))
return sm
if __name__=="__main__":
MainApp().run()
main.kv
CfgScreen:
<CfgScreen>:
name: "cfg"
sm_cfg: sm_cfg
scroll: scroll
screen_cfg_user_account: screen_cfg_user_account
canvas.before:
Color:
rgba: 242/255.00, 242/255.00, 242/255.00
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
orientation: "vertical"
MDTopAppBar:
title: "Topbar"
elevation: 10
md_bg_color: app.theme_cls.primary_color
specific_text_color: 242/255.00, 242/255.00, 242/255.00
canvas.before:
Color:
rgba: app.theme_cls.primary_color
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
orientation: "horizontal"
MDNavigationRail:
id: navigation_rail
md_bg_color: app.theme_cls.primary_color
selected_color_background: "#F2F2F2"
ripple_color_item: 242/255.00, 242/255.00, 242/255.00
specific_text_color: 242/255.00, 242/255.00, 242/255.00
icon_color_item_normal: 242/255.00, 242/255.00, 242/255.00
icon_color_item_active: app.theme_cls.primary_color
anchor: "center"
type: "unselected"
size_x: 0.3
MDNavigationRailItem:
icon: "account-details-outline"
MDNavigationRailItem:
icon: "account-card-outline"
MDNavigationRailItem:
icon: "database-settings-outline"
ScreenManager:
id: sm_cfg
canvas.before:
Color:
rgba: 242/255.00, 242/255.00, 242/255.00
Rectangle:
pos: self.pos
size: self.size
Screen:
name: "cfg_user_account"
MDLabel:
text: root.my_label
halign: "center"
MDScrollView:
id: scroll
size_hint: 0.9, 0.7
pos_hint:{'x': 0.05, 'center_y': 0.45}
RelativeLayout:
id: screen_cfg_user_account
#orientation: "vertical"
MDFloatingActionButtonSpeedDial:
data: root.data
root_button_anim: True
Anyone can tell me why is it not working? There is no error thrown either.
I recently started using kivy for my project.
I'm trying to make a simple digital coffee menu board.
I'm trying to display what a user have selected.
In MenuScreen, menu is presented to a user, which then a user can select.
After selection, I would like to move to another screen and display 'the selection' eg: Espresso
on top of the picture of a coffee cup.
I got to a stage where I can manually write a string value to be displayed.
But I wasn't able to display the selected name of the coffee by a user.
I'm literally stuck with this problem for 2 straight days or about 17hours of intense googling and reading documentations, but with my limited braincells, I wasn't able to solve it.
I've looked into binding, passing variables between 2 classes,etc.
Any help would be greatly appreciated!!
short version python code
class MenuScreen(Screen):
def __init__(self, **kwargs):
super(MenuScreen, self).__init__(**kwargs)
def buttonEspresso(self):
print ('Espresso Selected')
global selectedDrink
selectedDrink = self.coffeeName.text #<-------
sm.current = 'settings'
class SettingsScreen(Screen):
coffeeName = ObjectProperty(None)
def __init__(self, **kwargs):
super(SettingsScreen, self).__init__(**kwargs)
self.ids.coffeeName.text = selectedDrink #<-------
def backToMenu(self):
print('going back to menu')
sm.current = 'menu'
short version kivy code
:
coffeeName: coffeeName
GridLayout:
cols:2
GridLayout:
cols:2
Button:
id: coffeeName
text: 'Espresso'
on_press:
root.manager.transition = FadeTransition()
root.text = 'Espresso'
root.buttonEspresso()
<SettingsScreen>:
coffeeName: coffeeName
GridLayout:
cols:2
GridLayout:
cols:1
Button:
text: 'Back to menu'
size_hint: None, None
size: 200, 50
on_press:
root.manager.transition = SlideTransition(direction="left")
root.backToMenu()
Label:
id: coffeeName #<-------
text: 'coffeeName'
font_size: 70
size_hint: None, None
size: 960, 50
AnchorLayout:
anchor_x: 'center'
anchor_y: 'center'
Image:
source: 'cappuccino.png'
size_hint: None, None
size: 1000, 1000
If I select 'Espresso' then my desired outcome is
having 'Espresso' displayed in the red border.
Above image with myDesiredOutcome was made by editing
self.ids.coffeeName.text = selectedDrink #<-------
for illustration purpose
PythonCode
import kivy
from kivy.app import App
from kivy.logger import Logger
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.video import Video
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.properties import StringProperty
from kivy.properties import ObjectProperty
import subprocess
import os
from omxplayer.player import OMXPlayer
class Player(Video):
def __init__(self, **kwargs):
super(Player, self).__init__(**kwargs)
self.player = OMXPlayer('video.mp4','--loop')
self.state='play'
self.options={'eos': 'loop'}
self.bind(on_touch_down = self.on_stop)
def check(self):
Logger.info("film position:" + str(self.position))
def on_stop(self, *args):
print ('I have been clicked')
#self.state='stop' # stop the video
self.player.quit()
sm.current = 'menu' # switch to the other Screen
class MenuScreen(Screen):
#coffeeName = ObjectProperty(None)
def __init__(self, **kwargs):
super(MenuScreen, self).__init__(**kwargs)
def buttonEspresso(self):
print ('Espresso Selected')
global selectedDrink
selectedDrink = self.coffeeName.text #<-------
sm.current = 'settings'
def buttonAmericano(self):
print ('Americano Selected')
sm.current = 'settings'
def buttonCafeLatte(self):
print ('Cafe Latte Selected')
sm.current = 'settings'
def buttonCappuccino(self):
print ('Cappuccino Selected')
sm.current = 'settings'
def buttonCafeMocha(self):
print ('Cafe Mocha Selected')
sm.current = 'settings'
def buttonMochaccino(self):
print ('Mochaccino Selected')
sm.current = 'settings'
class SettingsScreen(Screen):
coffeeName = ObjectProperty(None)
def __init__(self, **kwargs):
super(SettingsScreen, self).__init__(**kwargs)
self.ids.coffeeName.text = selectedDrink #<-------
def backToMenu(self):
print('going back to menu')
sm.current = 'menu'
Builder.load_file('screenManager.kv')
sm = ScreenManager()
screen1 = Screen(name='video')
screen1.add_widget(Player())
sm.add_widget(screen1)
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(SettingsScreen(name='settings'))
class VideoPlayerApp(App):
def build(self):
return sm
if __name__ == "__main__":
video = VideoPlayerApp()
try:
video.run()
except KeyboardInterrupt:
video.stop()
os.system('killall dbus-daemon')
Kivy code
#:import FadeTransition kivy.uix.screenmanager.FadeTransition
#:import SlideTransition kivy.uix.screenmanager.SlideTransition
#:import GridLayout kivy.uix.gridlayout
<MenuScreen>:
coffeeName: coffeeName
GridLayout:
cols:2
GridLayout:
cols:2
Button:
id: coffeeName
text: 'Espresso'
on_press:
root.manager.transition = FadeTransition()
root.text = 'Espresso'
root.buttonEspresso()
Button:
text: 'Americano'
on_press:
root.manager.transition = FadeTransition()
root.buttonAmericano()
Button:
text: 'Cafe Latte'
on_press:
root.manager.transition = FadeTransition()
root.buttonCafeLatte()
Button:
text: 'Cappuccino'
on_press:
root.manager.transition = FadeTransition()
root.buttonCappuccino()
Button:
text: 'Cafe Mocha'
on_press:
root.manager.transition = FadeTransition()
root.buttonCafeMocha()
Button:
text: 'Mochaccino'
on_press:
root.manager.transition = FadeTransition()
root.buttonMochaccino()
GridLayout:
cols:2
Button:
text: 'Hot Chocolate'
on_press:
root.manager.transition = FadeTransition()
root.manager.current = 'settings'
#fading transition for video
Button:
text: 'Creamy Chocolate'
on_press:
root.manager.transition = FadeTransition()
root.manager.current = 'settings'
#fading transition for video
Button:
text: 'Express Coffee'
on_press:
root.manager.transition = FadeTransition()
root.manager.current = 'settings'
#fading transition for video
Button:
text: 'Green Tea'
on_press:
root.manager.transition = FadeTransition()
root.manager.current = 'settings'
#fading transition for video
Button:
text: 'Milk Tea'
on_press:
root.manager.transition = FadeTransition()
root.manager.current = 'settings'
#fading transition for video
Button:
text: 'Roibos Tea'
on_press:
root.manager.transition = FadeTransition()
root.manager.current = 'settings'
#fading transition for video
<SettingsScreen>:
coffeeName: coffeeName
GridLayout:
cols:2
GridLayout:
cols:1
Button:
text: 'Back to menu'
size_hint: None, None
size: 200, 50
on_press:
root.manager.transition = SlideTransition(direction="left")
root.backToMenu()
Label:
id: coffeeName #<-------
text: 'coffeeName'
font_size: 70
size_hint: None, None
size: 960, 50
AnchorLayout:
anchor_x: 'center'
anchor_y: 'center'
Image:
source: 'cappuccino.png'
size_hint: None, None
size: 1000, 1000
GridLayout:
cols:1
Label:
font_size: 70
text: 'Select a Payment Option'
size_hint: None, None
size: 960, 200
BoxLayout:
size_hint: None, None
size: 960, 50
ToggleButton:
text: 'Cash'
font_size: 50
on_press:
print('on_press')
ToggleButton:
text: 'UniPay'
font_size: 50
ToggleButton:
text: 'Bank Cards'
font_size: 50
BoxLayout:
Button:
text: 'Back to menu'
on_press:
root.manager.transition = SlideTransition(direction="left")
root.manager.current = 'menu'
I am trying to create an app of a game that i play with my friends.
I have this code and i want to loop the list "jugadores" in FourWindow.
import kivy
kivy.require('1.9.0')
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang.builder import Builder
from kivy.core.window import Window
Window.size = (300, 1280)
Jugadores = []
CantidadDeCartas = 0
Objetivo = 0
Manos = 0
class MainWindow(Screen):
cartas = ObjectProperty(None)
objetivo = ObjectProperty(None)
def btn(self):
CantidadDeCartas = int(self.cartas.text)
Objetivo = int(self.objetivo.text)
self.cartas.text = ""
self.objetivo.text = ""
class SecondWindow(Screen):
cartas = ObjectProperty(None)
objetivo = ObjectProperty(None)
class ThirdWindow(Screen):
def btn3(self):
Nombre = self.njugador.text
Jugadores.append(Nombre)
self.njugador.text = ""
self.jugador.text = str(Jugadores)
print(Jugadores)
def btn4(self):
self.njugador.text = ""
Jugadores.clear()
self.jugador.text = ""
def btn5(self):
Jugadores.reverse()
if len(Jugadores) != 0:
largo = Jugadores.count(self)
Jugadores.pop(largo)
Jugadores.reverse()
print(Jugadores)
self.jugador.text = str(Jugadores)
else:
self.jugador.text = ""
class FourWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
kv = Builder.load_file("tim4.kv")
class tim4App(App):
def build(self):
return kv
if __name__ == "__main__":
tim4App().run()
KIVY
WindowManager:
MainWindow:
SecondWindow:
ThirdWindow:
FourWindow:
<MainWindow>:
name: "main"
cartas : cartas
objetivo : objetivo
GridLayout:
cols:1
GridLayout:
cols: 2
Label:
text:"Cartas: "
TextInput:
id: cartas
multiline: False
input_type: "number"
input_filter: "int"
Label:
text:"Objetivo: "
TextInput:
id: objetivo
multiline: False
input_type: "number"
input_filter: "int"
Button:
text: "Siguiente>>"
on_release:
app.root.current= "second"
root.manager.screens[1].ids.carta.text = "Se juega con " + root.ids.cartas.text + " cartas"
root.manager.screens[1].ids.objetivo.text = "Se juega a " + root.ids.objetivo.text
root.manager.screens[3].ids.iduno.text = "Se juega con " + root.ids.cartas.text + " cartas"
root.manager.screens[3].ids.iddos.text = "Se juega a " + root.ids.objetivo.text
root.btn()
root.manager.transition.direction="left"
<SecondWindow>:
name: "second"
carta: carta
objetivo: objetivo
GridLayout:
cols:1
size: root.width, root.height
pos: 0, 0
Label:
id: carta
text: ""
Label:
id: objetivo
text: ""
GridLayout:
cols:2
Button:
text: "Ir Atrás"
on_release:
app.root.current= "main"
root.manager.transition.direction="right"
Button:
text: "Elegir Jugadores"
on_release:
app.root.current= "third"
root.manager.transition.direction="left"
<ThirdWindow>
name: "third"
njugador: njugador
jugador: jugador
empezar: empezar
GridLayout:
cols: 2
orientation: "horizontal"
GridLayout:
cols:1
TextInput:
id: njugador
text: "quien juega"
multiline: False
GridLayout:
cols:3
Button:
text: "Agregar Jugador"
on_press: root.btn3()
Button:
text:"Borrar Último"
on_press: root.btn5()
Button:
text:"Limpiar todo"
on_press: root.btn4()
GridLayout:
cols:1
orientation: "vertical"
Label:
id : jugador
text: ""
Button:
id: empezar
text:"Empezar Juego"
on_release:
app.root.current= "four"
root.manager.transition.direction="left"
<FourWindow>
name: "four"
iduno: iduno
iddos: iddos
idtres: idtres
GridLayout:
orientation:"horizontal"
rows: 3
Label:
id: iduno
text:""
Label:
id: iddos
text:""
Label:
id: idtres
text:"manos"
On FourWindow i want loop the list "Jugadores" to create labels. Theres is anyway of doing that through kv lenguage? Or how to do it on python file?
You can do it with an on_enter() method in your FourWindow class, or you can do it in kv by defining the on_enter method in kv. To do this, modify your FourWindow rule in the kv:
#: import Label kivy.uix.label.Label
<FourWindow>
name: "four"
iduno: iduno
iddos: iddos
idtres: idtres
on_pre_enter: for p in self.players: l=Label(text=p); grid.add_widget(l);
GridLayout:
id: grid # needed for the above code
rows: 3
Label:
id: iduno
text:""
Label:
id: iddos
text:""
Label:
id: idtres
text:"manos"
And modify your definition of the FourWindow class:
class FourWindow(Screen):
players = ObjectProperty(Jugadores)
The players object is just to provide access to the Jugadores list.
I am referring to this video and trying to replicate the same using KivyMD. Basically it is a simple app with the screen manager. Once you enter the password pswd it takes you to the next screen and on the release of the button, it comes back.
I am trying to replace the text filed with KivyMD TestRoundField
main.py file from the Tutorial
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
class MainWindow(Screen):
pass
class SecondWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
kv = Builder.load_file("my.kv")
class MyMainApp(App):
def build(self):
return kv
if __name__ == "__main__":
MyMainApp().run()
my.kv file from the tutorial - Password - pswd
WindowManager:
MainWindow:
SecondWindow:
<MainWindow>:
name: "main"
GridLayout:
cols:1
GridLayout:
cols:2
Label:
text: "Password"
TextInput:
id: passw
multiline: False
Button:
text: "Submit"
on_release:
app.root.current = "second" if passw.text == "pswd" else "main"
root.manager.transition.direction = "left"
<SecondWindow>:
name: "second"
Button:
text: "Go Back"
on_release:
app.root.current = "main"
root.manager.transition.direction = "right"
My Code
This is my main.py file -
from kivy.factory import Factory
from kivymd.app import MDApp
from kivy.lang import Builder
kivyFile = Builder.load_file("loginKivy.kv")
class MainApp(MDApp):
def __init__(self, **kwargs):
self.title = "KivyMD Examples - Round Text Field"
self.theme_cls.primary_palette = "BlueGray"
super().__init__(**kwargs)
def build(self):
self.root = Factory.Password()
return kivyFile
class Second_Screen(Screen):
pass
if __name__ == "__main__":
MainApp().run()
This is my loginKivy.kv file
#:set color_shadow [0, 0, 0, .2980392156862745]
#:set color_lilac [.07058823529411765, .07058823529411765, .14901960784313725, .8]
<MyMDTextFieldRound#MDTextFieldRound>
size_hint_x: None
normal_color: color_shadow
active_color: color_shadow
pos_hint: {"center_x": .5}
<Password#Screen>
canvas:
Color:
rgba: color_lilac
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
orientation: "vertical"
size_hint_y: None
height: self.minimum_height
spacing: dp(15)
pos_hint: {"center_x": .5, "center_y": .5}
MyMDTextFieldRound:
icon_type: "without"
hint_text: "Field without icon"
color: 1,0,1,1
I am confused on how to proceed further. What should I do next?
I suggest changing your build() method to:
def build(self):
return Builder.load_file("loginKivy.kv")
# sm = ScreenManager()
# sm.add_widget(Factory.Password())
# sm.add_widget(Second_Screen())
# return sm
Then you need to add the "Submit" and "Go Back" Buttons to your kv as well as the <Second_Screen> rule.
You can add those Buttons using kivy Button or kivyMD MDRaisedButton:
#:set color_shadow [0, 0, 0, .2980392156862745]
#:set color_lilac [.07058823529411765, .07058823529411765, .14901960784313725, .8]
ScreenManager:
Password:
Second_Screen:
<MyMDTextFieldRound#MDTextFieldRound>
size_hint_x: None
normal_color: color_shadow
active_color: color_shadow
pos_hint: {"center_x": .5}
<Password#Screen>
name: "main"
canvas:
Color:
rgba: color_lilac
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
orientation: "vertical"
size_hint_y: None
height: self.minimum_height
spacing: dp(15)
pos_hint: {"center_x": .5, "center_y": .5}
MyMDTextFieldRound:
id: passw
icon_type: "without"
hint_text: "Field without icon"
color: 1,0,1,1
MDRaisedButton:
text: "Submit"
pos_hint: {'center_x': 0.5}
on_release:
app.root.current = "second" if passw.text == "pswd" else "main"
root.manager.transition.direction = "left"
<Second_Screen>:
name: 'second'
MDRaisedButton:
text: "Go Back"
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
on_release:
app.root.current = "main"
root.manager.transition.direction = "right"
I have also added the ScreenManager structure allowing the build() method to just return the result of loading the kv file.
The documentation for kv can be found at kivy.lang