Reputation: 23
Here is my code;
Main.py
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.network.urlrequest import UrlRequest
from kivy.uix.listview import ListItemButton
from kivy.factory import Factory
import sqlite3
from kivy.uix.label import Label
class LoginRoot(BoxLayout):
username = ObjectProperty()
password = ObjectProperty()
def login_form(self):
username = (self.username.text)
password = (self.password.text)
f = open("text/name.txt", "w")
f.write("%s" % username)
f.close()
f = open("text/pass.txt", "w")
f.write("%s" % password)
f.close()
def log_form(self):
print ("Hi")
def id_form(self):
self.clear_widgets()
current_weather = Factory.Code()
self.add_widget(current_weather)
conn = sqlite3.connect('db/test')
c = conn.cursor()
se = open("text/name.txt", "r")
username = se.read()
c.execute("SELECT password from userin where username = '%s'" % username)
se.close()
d = c.fetchone()
f = open("yes.txt", "w")
f.write("%s" % d)
f.close()
d = open("yes.txt", "r")
d = d.read()
ser = open("text/pass.txt", "r")
password = ser.read()
if d == password:
usernow = ("%s" % username)
print usernow
class DisocialApp(App):
pass
class Code(BoxLayout):
idcode = ObjectProperty()
def ids_form(self):
print (self.idcode.text)
if __name__ == "__main__":
DisocialApp().run()
Disocial.kv LoginRoot:
<LoginRoot>:
orientation: "vertical"
username: user_input
password: pass_input
BoxLayout:
height: "40dp"
size_hint_y: None
TextInput:
id: user_input
size_hint_x: 50
focus: True
multiline: False
TextInput:
id: pass_input
size_hint_x: 50
focus: True
multiline: False
Button:
text: "Login"
size_hint_x: 25
on_press: root.login_form()
Button:
text: "Check Places"
size_hint_x: 25
on_press: root.id_form()
<Code@BoxLayout>:
orientation: "vertical"
idcode: id_input
BoxLayout:
height: "40dp"
size_hint_y: None
TextInput:
id: id_input
size_hint_x: 50
focus: True
multiline: False
Button:
text: "Login"
size_hint_x: 25
on_press: app.root.ids_form()
I know get this error;
File "/home/seandowney/PycharmProjects/SchoolShow/disocial.kv", line 43, in <module>
on_press: app.root.ids_form()
AttributeError: 'LoginRoot' object has no attribute 'ids_form'
What I want is to enter the text from (self.idcode.text) and print it.
I have tried multiple things but to no avail and I am getting extremely confused. I believe that idcode = ObjectProperty() should behave like username and password?
Upvotes: 0
Views: 1641
Reputation: 113978
you define something like this in your kv file
<RootLogin>
....
<Code@BoxLayout>
idcode = ...
this is roughly equivelent to
class RootLogin:
...
class Code(BoxLayout):
idcode = ...
so why would you think you could do this
a = RootLogin()
a.idcode #idcode is an attribute of Code ... not RootLogin
Im not sure what you are expecting this stuff to do so I cant help much more than that
Upvotes: 0
Reputation: 29460
idcode = ObjectProperty()
This is the only place that you set idcode for that class. The default value is None, therefore you get the given error.
You do set the idcode property of your Code class, but never access this. I'm not sure what you think should be accessing it, please elaborate on what you think should happen if it's still not clear to you what is wrong.
Upvotes: 1