I am trying to pass a value from InputText
as shown below. But I always get an empty string. If I write InputText (text = 'test')
, then the word test is always transmitted and not what I enter. How to get in the UserAcount
class the value that I enter into InputText()
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.metrics import dp
import sqlite3
conn = sqlite3.connect('diplom.sqlite', check_same_thread = False)
class EntryMenu(Screen):
def __init__(self, **kw):
super(EntryMenu, self).__init__(**kw)
box = BoxLayout(padding=150,orientation='vertical')
self.login = TextInput(text='', multiline=False)
box.add_widget(self.login)
self.password = TextInput(text='', multiline=False)
box.add_widget(self.password)
self.error = Label(text="")
box.add_widget(self.error)
box.add_widget(Button(text='Entry', on_press=self.buttonClicked))
self.add_widget(box)
def buttonClicked(self,btn):
self.error.text=''
with conn:
cursor = conn.cursor()
sql =f'''SELECT username,password
FROM user
WHERE username = '{self.login.text}';
'''
cursor.execute(sql)
results = cursor.fetchall()
if results:
if self.password.text==results[0][1]:
set_screen('user_acount')
elif self.password.text!=results[0][1]:
self.error.text = "error password"
else:
self.error.text = "can not search user"
class UserAcount(Screen):
def __init__(self,login, **kw):
super(UserAcount, self).__init__(**kw)
box = BoxLayout(orientation='vertical')
self.login=login
name = Label(text=self.login)
box.add_widget(name)
back_button = Button(text='Exit', on_press=lambda x:
set_screen('menu'), size_hint_y=None, height=dp(40))
box.add_widget(back_button)
self.add_widget(box)
def set_screen(name_screen):
sm.current = name_screen
sm = ScreenManager()
sm.add_widget(EntryMenu(name='menu'))
sm.add_widget(UserAcount(EntryMenu().login.text,name='user_acount'))
class MyApp(App):
def __init__(self, **kvargs):
super(MyApp, self).__init__(**kvargs)
def build(self):
return sm
if __name__=="__main__":
MyApp().run()
Please tell me what I'm missing. Thanks in advance
from Getting a value from InputText in another class. kivy
No comments:
Post a Comment