Kivymd on_release Button the action for next step with MDCard does not work - python-3.x

I'm trying to make the button click on_release: app.proximo () have the action to go to the next card MDFloatLayout, but I'm not getting it, could someone help me how could it work?
Below the main.py file, where to start the app, main.kv file, where is the main app and finally the dashboard.kv file where I am calling my card inside the app
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
class DashBoard(Screen):
pass
class FirstScreen(Screen):
pass
class Lavanderia(MDApp):
def build(self):
self.title="Texto Titulo"
self.theme_cls.primary_palette = "LightBlue"
return Builder.load_file("main.kv")
def proximo(self):
self.root.ids.carousel.load_next(mode="proximo")# Próximo Card
def fecharApp(self):
self.stop()# Fecha Aplicativo
Lavanderia().run()
#:import rgba kivy.utils.get_color_from_hex
#: include dashboard.kv
#: include firstscreen.kv
NavigationLayout:
id: nav_layout
ScreenManager:
Screen:
BoxLayout:
orientation:'vertical'
MDToolbar:
title: app.title
elevation:10
left_action_items:[["menu", lambda x: nav_drawer.set_state()]]
ScreenManager:
id: screen_manager
DashBoard:
id:dashboard
name:"dashboard"
FirstScreen:
id:first_screen
name:"first_screen"
MDNavigationDrawer:
id: nav_drawer
BoxLayout:
orientation:'vertical'
padding:"8dp"
spacing:"8dp"
Image:
pos_hint:{"x":.24,"y":.0}
size_hint: None, None
size:dp(146), dp(158)
source:"images/logo.png"
ScrollView:
MDList:
OneLineIconListItem:
text:"Tela 1"
on_release:
screen_manager.current = "dashboard"
nav_drawer.set_state()
IconLeftWidget:
icon:"dishwasher"
OneLineIconListItem:
text:"Tela 2"
on_release:
screen_manager.current = "first_screen"
nav_drawer.set_state()
IconLeftWidget:
icon:"dishwasher"
<DashBoard>:
MDFloatLayout:
MDCard:
size_hint: dp(.45), dp(.8)
pos_hint:{"center_x": .5, "center_y": .5}
Carousel:
id:carousel
MDFloatLayout:
MDTextField:
hint_text:"Texto 1"
size_hint_x:dp(.8)
pos_hint:{"center_x": .5, "center_y": .48}
MDRaisedButton:
text: "Proximo"
size_hint_x:dp(.8)
pos_hint:{"center_x":.5,"center_y":.2}
on_release: app.proximo() # Proximo step
MDFloatLayout:
MDLabel:
text:"Texto Final Conclusão"
theme_text_color:"Custom"
bold:True
pos_hint:{"center_x":.68,"center_y":.5}
font_style:"H5"
MDRaisedButton:
text: "Fechar Aplicativo"
text_color:rgba("#00FF69")
size_hint_x:dp(.8)
pos_hint:{"center_x":.5,"center_y":.4}
md_bg_color:rgba("#333333")
on_release: app.fecharApp() #fechar Aplicativo

You are trying to ger the carrousel through the root screen, but it is inside the dashboard screen.
So you will have to navigate there first, and only then you can call your function.
def proximo(self):
dashboard = self.root.ids.dashboard
carousel = dashboard.ids.carousel
carousel.load_next(mode="proximo")
# Same as
# self.root.ids.dashboard.ids.carousel.load_next(mode="proximo")

Related

pyrebase auth and kivy signup and login pages

i have been working on a python app using kivy and firebase authentication.. following youtube tutorials really....
i can get it so when the button is pressed on the signup screen and there is a valid email and password .. the user is created in firebase realtime db and it prints the idToken
however, when the user enters an invalid email password the code errors which i have used the Try and Except.. but i cant for the life of me link that Except to my .kv file where i have the label with id:login_message for the error message to be shown on the screen.
by chucking in some random letters into the signup inputs.. i can get it to print invalid
enter image description here
code is below...
what goes under the except in the class MyFirebaseSignup: and in the except: to print the label with id: login_message in the signup.kv file
LoginSignup.py
import pyrebase
from kivy.core.text import LabelBase
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen,ScreenManager
from kivymd.app import MDApp
from kivy.app import App
import requests
import json
Window.size = (310, 580)
config = {
"apiKey": "AIzaSyB8f5Py7E60rlCtpAaqXzpmWSgHN9vxfrc",
"authDomain": "fir-python-demo-39212.firebaseapp.com",
"databaseURL": "https://fir-python-demo-39212-default-rtdb.firebaseio.com",
"storageBucket": "fir-python-demo-39212.appspot.com",
}
firebase = pyrebase.initialize_app(config)
auth = firebase.auth()
class MyFirebaseSignup:
def sign_up(self, username, email, password, login_message=None):
try:
user = auth.create_user_with_email_and_password(email, password)
data = {"email": email, "password": password, "idToken": True}
info = auth.get_account_info(user["idToken"])
auth.send_email_verification(user["idToken"])
password = data.get("password")
print("Successfully created account")
except:
print("Invalid")
#App.get_running_app().root.ids["signup_screen"].ids["signup_screen"].text = MyLabel ..... doesnt work
#app..... id: SignUpError ---- display error message on signin page
pass
class MyFirebaseLogin():
def Login(self, email, password):
try:
login = auth.sign_in_with_email_and_password(email, password)
print("Successfully Logged in")
except:
print("invalid")
pass
class MainScreen(Screen):
pass
class LoginScreen(Screen):
pass
class SignupScreen(Screen):
pass
class LoginSignup(MDApp):
def build(self):
screen_manager = ScreenManager()
screen_manager.add_widget(Builder.load_file("main.kv"))
screen_manager.add_widget(Builder.load_file("signup.kv"))
screen_manager.add_widget(Builder.load_file("login.kv"))
self.my_firebasesignup = MyFirebaseSignup()
self.my_firebaselogin = MyFirebaseLogin()
return screen_manager
if __name__ == "__main__":
LoginSignup().run()
signup.kv
<SignupScreen>:
MDScreen:
name: "signup"
id: signup
MDFloatLayout:
MDLabel:
id: SignUpError
font_size: "18sp"
pos_hint: {"center_x":.5,"center_y":.73}
halign: "center"
color: (1,0,0,1)
MDFloatLayout:
size_hint: .7,.07
pos_hint: {"center_x":.5,"center_y":.68}
TextInput:
id: login_username
hint_text: "Username"
size_hint_y: .75
pos_hint: {"center_x":.43,"center_y":.5}
MDFloatLayout:
pos_hint: {"center_x":.45,"center_y":.0}
size_hint_y: .03
md_bg_color: rgba(178,178,178,255)
MDFloatLayout:
size_hint: .7,.07
pos_hint: {"center_x":.5,"center_y":.56}
TextInput:
id: login_email
hint_text: "Email"
size_hint_y: .75
pos_hint: {"center_x":.43,"center_y":.5}
MDFloatLayout:
pos_hint: {"center_x":.45,"center_y":.0}
size_hint_y: .03
md_bg_color: rgba(178,178,178,255)
MDFloatLayout:
size_hint: .7,.07
pos_hint: {"center_x":.5,"center_y":.44}
TextInput:
id: login_password
hint_text: "Password"
Button:
text: "SIGNUP"
size_hint: .66, .065
pos_hint: {"center_x":.5,"center_y":.3}
background_color: 0,0,0,0
font_name: "BPoppins"
canvas.before:
Color:
rgb: rgba(52,0,231,255)
RoundedRectangle:
size: self.size
pos: self.pos
radius: [5]
on_release:
print("Sign up", login_email.text, login_password.text)
app.my_firebasesignup.sign_up(login_username.text,login_email.text,login_password.text)
youtube, google, random code

Blank White space overlapping KivyMD ImageList from MDToolbar

I am practicing KivyMD ImageList, and the imagelist is been overlayed by a blank space coming from MDBottomAppbar.
Here's what it looks like:
Please how do I remove the white blank space that is above MDBottomAppbar and overlapping Imagelist. Here's my code.. Thanks in Advance!
from kivymd.app import MDApp
from kivy.lang.builder import Builder
from kivy.core.window import Window
Window.size = (330, 500)
kv = '''
<MyTile#SmartTileWithLabel>
size_hint_y: None
height: "240dp"
BoxLayout:
orientation: "vertical"
md_bg_color: (240/255, 240/255, 240/255, 1)
MDToolbar:
id: success_screen_toolbar
title: "Project"
right_action_items: [["progress-check", lambda x: x]]
ScrollView:
size_hint_y: None
size: "280dp", "360dp"
pos_hint: {"center_x": .5, "center_y": .6}
height: root.height - success_screen_toolbar.height - dp(90)
y: root.height - success_screen_toolbar.height - dp(50)
elevation: 8
MDGridLayout:
cols: 1
adaptive_height: True
padding: dp(4), dp(4)
spacing: dp(4)
MyTile:
source: "C:/Users/HP USER/Downloads/bella_baron.jpg"
text: "[size=26]Cat 1[/size]\\n[size=14]cat-1.jpg[/size]"
MyTile:
source: "C:/Users/HP USER/Downloads/bella_baron.jpg"
text: "[size=26]Cat 2[/size]\\n[size=14]cat-2.jpg[/size]"
tile_text_color: app.theme_cls.accent_color
MyTile:
source: "C:/Users/HP USER/Downloads/bella_baron.jpg"
text: "[size=26][color=#ffffff]Cat 3[/color][/size]\\n[size=14]cat-3.jpg[/size]"
tile_text_color: app.theme_cls.accent_color
MDBottomAppBar:
MDToolbar:
id: success_screen_bottomappbar
icon: "magnify"
on_action_button: x
type: 'bottom'
mode: 'center'
elevation: '8dp'
left_action_items: [["calendar-text", lambda x: x], ["account-group", lambda x: x]]
right_action_items: [["magnify", lambda x: x], ["menu", lambda x: x]]
'''
class Main(MDApp):
def build(self):
return Builder.load_string(kv)
Main().run()
Use the following please, I have changed a few things and a few main widgets in your code because they added additional space that was not being used and that caused the white space in the body of the app, so here is the code by jbsidis:
from kivymd.app import MDApp
from kivy.lang.builder import Builder
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
Window.size = (330, 500)
kv = '''
#:import MDTextField kivymd.uix.textfield.MDTextField
<MyTile#SmartTileWithLabel>
size_hint_y: None
height: "240dp"
<S>:
MDTextFieldRound:
pos_hint: {"center_x": .5, "center_y": .95}
normal_color : [1,1,1,.1]
color_active : [1,1,1,1]
size_hint: .8, .07
hint_text : 'Search a product...'
icon_left : 'magnify'
Screen:
FloatLayout:
BoxLayout:
id: m5
pos_hint: {"center_x": .5, "center_y": .371} #this will change if you change this Window.size = (330, 500)
orientation: "vertical"
ScrollView:
MDGridLayout:
cols: 1
adaptive_height: True
padding: dp(4), dp(4)
spacing: dp(4)
MyTile:
source: "Photos/pro.jpg"
text: "[size=26]jbsidis[/size]\\n[size=14]cat-1.jpg[/size]"
MyTile:
source: "Photos/pro.jpg"
text: "[size=26]jbsidis[/size]\\n[size=14]cat-2.jpg[/size]"
tile_text_color: app.theme_cls.accent_color
MyTile:
source: "Photos/pro.jpg"
text: "[size=26][color=#ffffff]jbsidis[/color][/size]\\n[size=14]cat-3.jpg[/size]"
tile_text_color: app.theme_cls.accent_color
MyTile:
source: "a11.png"
text: ""
tile_text_color: [0,0,0,0]
FloatLayout:
AnchorLayout:
pos_hint: {"center_x": .5, "center_y": .9}
MDTextButton:
halign: "center"
text: "\\n\\n\\n\\n\\n\\n\\nLoading more...\\n\\n"
MDSpinner:
size_hint: .1,.1
MDToolbar:
id: success_screen_toolbar
title: "Project"
pos_hint: {"top": 1}
right_action_items: [["progress-check", lambda: print(6)]]
MDBottomAppBar:
MDToolbar:
id: success_screen_bottomappbar
icon: "magnify"
on_action_button: root.add_widget(app.sbar())
type: 'bottom'
mode: 'center'
#elevation: '8dp'
left_action_items: [["calendar-text", lambda: print(6)], ["account-group", lambda: print(6)]]
right_action_items: [["magnify", lambda: print(6)], ["menu", lambda: print(6)]]
'''
class blanks1(BoxLayout):
pass
class S(FloatLayout):
pass
class Main(MDApp):
def build(self):
return Builder.load_string(kv)
def sbar(self):
self.root.ids.success_screen_toolbar.md_bg_color=[1,1,1,1]
return S()
Main().run()
I also added the function to add the search bar on top when we press the magnified glass icon at the bottom bar, I added an empty image at the bottom of the pictures so you can show your app is loading more results, hope this is helpful for you and everybody, greetings from El Salvador, picture (something else, the a11.png image is a blank transparent png image, the last should be an empty image to extend the scroll area otherwise the bottom bar will hide it, this is something that most operating systems implement but we cannot know because we don't see the source code, watch my youtube channel: https://www.youtube.com/channel/UCIMmPyY7XjWHk1AHlR_UdWQ ):

KivyMD on changing screen not creating MDList Items widget using root.ids and showing error

I am trying build an app in Python using Kivymd and i just started learning this kivymd framework so the problem i am facing is when i am trying to change screen from LoginScreen to HomeScreen, it raises error. I am unable to understand what's wrong in my code.
I wanted it to change screen to HomeScreen and then show the list on pressing button 'Join Chat'.
Here is the code:
main.py
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen,ScreenManager
from kivymd.uix.list import MDList, OneLineIconListItem,IconLeftWidget
class LoginScreen(Screen):
pass
class HomeScreen(Screen):
pass
class DemoApp(MDApp):
def build(self):
self.theme_cls.theme_style="Dark"
self.sm=ScreenManager()
self.sm.add_widget(LoginScreen(name="login"))
self.sm.add_widget(HomeScreen(name="home"))
screen=Builder.load_file("helper_file.kv")
return screen
def do_login(self):
self.sm.current = "home"
for i in range(20):
st_name="student "
list_item = OneLineIconListItem(text=f"student {str(i)}")
list_item.add_widget(IconLeftWidget(icon= "alpha-a-box"))
self.root.ids.users_lst.add_widget(list_item)
DemoApp().run()
helper_file.kv
ScreenManager:
LoginScreen:
HomeScreen:
<LoginScreen>:
name: "login"
Screen:
MDLabel:
text: "Demo App"
halign: "center"
pos_hint: {"center_x": .5, "center_y": .8}
theme_text_color: "Primary"
MDTextField:
hint_text: "Enter username"
helper_text: "to join the chat (test mode)"
helper_text_mode: "on_focus"
icon_right: "android"
icon_right_color: app.theme_cls.primary_color
pos_hint:{'center_x': 0.5, 'center_y': 0.5}
size_hint_x:None
width:311
MDRoundFlatButton:
text: "Join Chat"
pos_hint: {"center_x": .5, "center_y": .4}
on_release: app.do_login()
MDLabel:
text: "This is testing mode only"
halign: "center"
pos_hint: {"center_x": .5, "center_y": .2}
theme_text_color:"Hint"
<HomeScreen>:
name: "home"
Screen:
BoxLayout:
orientation: "vertical"
MDToolbar:
title: "Demo Chat Application"
ScrollView:
MDList:
id: users_lst
On running this, the login screen working well but on pressing the button 'Join Chat' it raises the following error:
self.root.ids.users_lst.add_widget(list_item)
File "kivy\properties.pyx", line 864, in kivy.properties.ObservableDict.__getattr__
AttributeError: 'super' object has no attribute '__getattr__'
| 1 |
class HomeScreen(Screen):
pass
<HomeScreen>:
name: "home"
Screen:
BoxLayout:
orientation: "vertical"
MDToolbar:
title: "Demo Chat Application"
ScrollView:
MDList:
id: users_lst
You have a screen which has a screen, that's not what you want to do.
<HomeScreen>:
name: "home"
BoxLayout:
orientation: "vertical"
MDToolbar:
title: "Demo Chat Application"
ScrollView:
MDList:
id: users_lst
#######################################################
#######################################################
| 2 |
Parent doesn't have access of the id of inner children children's. (Not clear I know, So I'm gonna give you a lot of print to help you understand).
def do_login(self):
self.root.current = "home"
for i in range(20):
st_name = "student "
list_item = OneLineIconListItem(text=f"student {str(i)}")
list_item.add_widget(IconLeftWidget(icon="alpha-a-box"))
print("this is my App:", self)
print("this is my ScreenManager:", self.sm)
print("this is my global app visual widget (which is equal to ScreenManager here):", self.root)
print("this is the ScreenManager's dictionnary containing the widgets referenced with their id:", self.root.ids)
print("this is the current Screen:",self.root.current_screen)
print("this is current Screen dictionnary containing the widgets referenced with their id:", self.root.current_screen.ids)
print("this is the actual MDList", self.root.current_screen.ids["users_lst"])
self.root.current_screen.ids["users_lst"].add_widget(list_item)

How to change screen by calling a method in Python Kivy

I'm new to kivy and I want to change my screen by clicking the image. I used the ButtonBehavior and call the on_press method of my class ImageButton but I can't figure it out what code to put. I tried on_press: screen_manager.current = 'window1' on my kivy file but its not working
Python Code
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.image import Image
from kivy.uix.behaviors import ButtonBehavior
class Window1(Screen):
pass
class Window2(Screen):
pass
class WindowManager(ScreenManager):
pass
class ImageButton(ButtonBehavior, Image):
def on_press(self):
# what to call
class Phone(FloatLayout):
pass
class MyApp(App):
def build(self):
return Phone()
if __name__ == '__main__':
MyApp().run()
kv file
<Phone>:
AnchorLayout:
anchor_x: 'center'
anchor_y: 'top'
WindowManager:
id: screen_manager
size_hint: 1, 0.9
anchor_y: 'top'
transition: FadeTransition()
Window1:
Window2:
AnchorLayout:
anchor_x: 'center'
anchor_y: 'bottom'
BoxLayout:
canvas:
Color:
rgba: 228, 241, 254, 1
Rectangle:
size: self.size
orientation: 'horizontal'
size_hint: 1, .1
ImageButton:
source: 'pic1.png'
on_press: self.on_press()
ImageButton:
source: 'pic2.png'
on_press: self.on_press()
<Window1>:
name: 'window1'
Label:
text: 'Window1'
<Window2>:
name: 'window2'
Label:
text: 'Window2'
Some one help me on this.. what im missing is in my kv file i should put
on_press: app.root.ids._screen_manager.current = 'window1'
Here is the explanation
When the kv code is parsed, the id fields go into a dict called ids, that stores pointers to the widget objects.
Each kivy rule has a sperate name space for ids.
Breaking it down:
app.root.ids.screen_manager
app is your app
root is the root widget, Phone
ids is the dict of ids defined at the root level
Credit for Elliot Garbus

How to change text of label in a screen when I press a button in another screen in Kivy

I am new to Kivy, so I have a question that I want to develop two screen in Kivy, the first one is about entering user details and passwords (no authentication, at this moment) and then second screen displays the user name (entered at the previous screen) and displays user name along with other widgets.
The basic idea is to get the value of a user form userlogin screen and display it to another screen.
Here is my code,
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import StringProperty # #UnresolvedImport
class LoginScreen(Screen):
text = StringProperty()
def change_text(self):
self.text = ''
self.manager.current = 'StocksGUIScreen'
class StocksGUIScreen(Screen):
label_text = StringProperty('')
#pass
class PortfolioUIApp(App):
#user_name = StringProperty()
pass
PortfolioUIApp().run()
Here is my .kv file:
ScreenManager:
id: screen_manager
LoginScreen:
id: login_screen
name: 'LoginScreen'
manager: screen_manager
StocksGUIScreen:
id: stocks_gui
name: 'StocksGUIScreen'
manager: screen_manager
label_text: login_screen.text
<LoginScreen>:
BoxLayout:
orientation: 'vertical'
BoxLayout:
Label:
text: "User Name"
size_hint: 0.3,0.2
#pos: root.x, root.top-self.height
color: 0,1,0,1
TextInput:
id: user_name
size_hint: 0.3,0.2
#on_text: root.user_name
BoxLayout:
Label:
text: "Password"
size_hint: 0.3,0.2
TextInput:
id: pass_word
password: True
size_hint: 0.3,0.2
BoxLayout:
Button:
text: 'Log In'
size_hint: 0.3,0.2
on_press:
#root.manager.current = 'StocksGUIScreen'
root.label_text: user_name
root.change_text()
Button:
text: 'Cancel'
size_hint: 0.3,0.2
on_release: app.stop()
<StocksGUIScreen>:
BoxLayout:
orientation: 'vertical'
BoxLayout:
orientation: 'horizontal'
TextInput:
size_hint_x: 50
id: ticker_search
Button:
text: "Go"
size_hint_x: 25
on_press: root.search_stock()
id: search_box
Label:
text: root.label_text
size_hint_x: 25
BoxLayout:
height: "10dp"
size_hint_y: 5
Label:
size_hint_x: .2
size_hint_y: .1
text: "Advice"
color: [1,0,0,1]
text_size: self.size
halign: 'left'
valign: 'top'
ScrollView:
size: self.size
GridLayout:
id: layout_content
size_hint_y: None
cols: 1
row_default_height: '20dp'
row_force_default: True
spacing: 0, 0
padding: 0, 0
color: [1,0,0,1]
Label:
text: "Lorem ipsum dolor sit amet"*10
id: advice_message
text_size: self.size
halign: 'left'
valign: 'top'
BoxLayout:
height: "10dp"
size_hint_y: 10
Label:
size_hint_x: .2
size_hint_y: .1
text: "Graphical Stuff"
id: graphical_stuff
text_size: self.size
halign: 'left'
valign: 'top'
AsyncImage:
source: "abc.png"
id: graphical_stuff
allow_stretch: True
keep_ratio: False
pos: 200,300
size: root.width*0.5,root.height*0.2
BoxLayout:
orientation: 'horizontal'
Button:
text: 'My settings button'
Button:
text: 'Back to Log in screen'
on_press: root.manager.current = 'LoginScreen'
What is wrong in this code, any help/guidance would be highly appreciated plz
If you want this setup, you can set an attribute on the first screen. Access it by id in your second screen.
from kivy.app import App
from kivy.uix.screenmanager import Screen
from kivy.lang import Builder
from kivy.properties import StringProperty
class Screen1(Screen):
username = StringProperty("")
class Screen2(Screen):
username = StringProperty("")
root = Builder.load_string('''
<Screen1>:
BoxLayout:
orientation: "vertical"
TextInput:
id: username
Button:
text: "Login"
on_release: root.username = username.text; root.manager.current = "screen2"
<Screen2>:
name: "screen2"
Label:
text: root.username
ScreenManager:
Screen1:
id: loginscreen
Screen2:
username: loginscreen.username
''')
class MyApp(App):
def build(self):
return root

Resources