Я пытаюсь, чтобы на моей домашней странице отображалось имя пользователя после входа в систему. Сначала я получал эту ошибку,
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 14 supplied.
Я перестал получать эту ошибку после того, как изменил (self.current)
на (self.current,)
. Тем не менее, я получаю эту ошибку,
TypeError: can only concatenate str (not "sqlite3.Cursor") to str
Я попытался решить эту проблему, задав пользователю строку "Olá " + str(user)
Это только отображало Olá <sqlite3.Cursor object at 0x00000219024FA650>
.
main. py
class HomeScreen(Screen):
usr = ObjectProperty()
email = ObjectProperty()
current = ""
def on_enter(self, *args):
user = cur.execute('SELECT user FROM id WHERE email =?', (self.current,))
self.usr.text = "Olá " + user
print("Olá " + user)
class LoginScreen(Screen):
email = ObjectProperty()
password = ObjectProperty()
def verify_user(self):
cur.execute('SELECT * from id WHERE email="%s" AND password="%s"' % (self.email.text, self.password.text))
if cur.fetchone() is not None:
HomeScreen.current = self.email.text
sm.current = 'Casa'
self.reset()
else:
self.invalidLogin()
self.reset()
def reset(self):
self.email.text = ""
self.password.text = ""
def invalidLogin(self):
pop = Popup(title='Invalid Login',
content=Label(text='Invalid username or password.'),
size_hint=(None, None), size=(400, 400),separator_color=(1.36, 0, .27, 1))
pop.open()
self.email.text = ""
self.password.text = ""
kv = Builder.load_file("main.kv")
sm = ScreenManagement()
screens = [LoginScreen(name="login"), SignUpScreen(name="signup"),HomeScreen(name="Casa"),SearchScreen(name="Search")]
for screen in screens:
sm.add_widget(screen)
sm.current = 'login'
con = sql.connect('userlog.db')
cur = con.cursor()
class MainApp(App):
def build(self):
return sm
if __name__ == "__main__":
MainApp().run()
main.kv
HomeScreen>:
name: "Casa"
usr: usr
email: email
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: 'images/LightBackgroundReOr.png'
FloatLayout:
GridLayout:
pos_hint: {"top": 1, "left": 1}
size_hint: 1, .1
Image:
id: imageView
source: 'images/uaiLogoReOr.png'
size_hint: 0.25, 0.25
pos_hint: {'center_x':.5, 'y':.7}
Label:
id: usr
pos_hint:{"x": 0.1, "top":0.9}
size_hint:0.8, 0.2
text: "Olá "
Label:
id: email
pos_hint:{"x": 0.1, "top":0.9}
size_hint:0.8, 0.2
text: ""
...