Я получаю следующую ошибку TypeError: объект 'NoneType' не может быть подписан. Прочитав об этой ошибке, я понимаю, что ошибка связана с попыткой доступа к значению None, но приведенная ниже ошибка на самом деле не является чем-то в моем коде, похоже, она исходит из пакета kivy? Любые намеки на то, что может быть не так?
Traceback (most recent call last):
File "C:/Users/callu/OneDrive/Documents/Voting app/main.py", line 81, in <module>
kv = Builder.load_file("my.kv")
File "C:\Users\callu\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\lang\builder.py", line 301, in load_file
return self.load_string(data, **kwargs)
File "C:\Users\callu\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\lang\builder.py", line 368, in load_string
parser = Parser(content=string, filename=fn)
File "C:\Users\callu\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\lang\parser.py", line 401, in __init__
self.parse(content)
File "C:\Users\callu\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\lang\parser.py", line 510, in parse
objects, remaining_lines = self.parse_level(0, lines)
File "C:\Users\callu\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\lang\parser.py", line 614, in parse_level
level + 1, lines[i:], spaces)
File "C:\Users\callu\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\lang\parser.py", line 614, in parse_level
level + 1, lines[i:], spaces)
File "C:\Users\callu\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\lang\parser.py", line 673, in parse_level
if current_property[:3] == 'on_':
TypeError: 'NoneType' object is not subscriptable
import kivy
from kivy.app import App
from kivy.properties import ObjectProperty
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from kivy.uix.popup import Popup
import sqlite3
conn = sqlite3.connect(":memory:")
cur = conn.cursor()
cur.execute("""CREATE TABLE votes (email NOT NULL, password NOT NULL, votes_yes INTEGER, votes_no INTEGER)""")
class LoginWindow(Screen):
email = ObjectProperty(None)
password = ObjectProperty(None)
def login(self):
with conn:
cur.execute("SELECT * FROM votes WHERE email = ? And password = ?, (self.email.text, self.password.text)")
result = cur.fetchone()
if result:
self.reset()
sm.current = "voting"
else:
invalid_login()
def reset(self):
self.email.text = ""
self.password.text = ""
class VotingWindow(Screen):
email = ObjectProperty()
def yes_btn(self):
with conn:
cur.execute("UPDATE votes set vote_yes = 1 WHERE email = self.email.text")
def no_btn(self):
with conn:
cur.execute("UPDATE votes set vote_no = 1 WHERE email = self.email.text")
class CreateAccountWindow(Screen):
email = ObjectProperty()
password = ObjectProperty()
def create_btn(self):
with conn:
results = cur.execute("SELECT * FROM votes WHERE email = ?, (self.email.text,)")
if results:
invalid_form()
else:
cur.execute("INSERT into votes VALUES(email = ?, password = ?), (self.email.text, self.password.text)")
self.reset()
def reset(self):
self.email.text = ""
self.password.text = ""
class WindowManager(ScreenManager):
pass
def invalid_login():
pop = Popup(title='Invalid Login',
content=Label(text='Invalid username or password.'),
size_hint=(None, None), size=(400, 400))
pop.open()
def invalid_form():
pop = Popup(title='Error',
content=Label(text='An account already exists with that email address'),
size_hint=(None, None), size=(400, 400))
pop.open()
kv = Builder.load_file("my.kv")
sm = WindowManager()
screens = [LoginWindow(name="login"), CreateAccountWindow(name="create account"), VotingWindow(name="voting")]
for screen in screens:
sm.add_widget(screen)
sm.current = "login"
class MyApp(App):
def build(self):
return sm
if __name__ == '__main__':
MyApp().run()
conn.close()
WindowManager:
LoginWindow:
VotingWindow:
CreateAccountWindow:
<LoginWindow>:
name: "login"
email: email
password: password
FloatLayout:
FloatLayout:
Label:
text: "Email: "
size_hint: 0.1, 0.1
pos_hint: {"x": 0.2, "top": 0.9}
TextInput:
id: email
multiline: False
size_hint: 0.4, 0.1
pos_hint: {"x": 0.4, "top": 0.9}
Label:
text: "Password: "
size_hint: 0.1, 0.1
pos_hint: {"x": 0.2, "top": 0.8}
TextInput:
id: password
multiline: False
size_hint: 0.4, 0.1
pos_hint: {"x": 0.4, "top": 0.8}
Button:
text: "Login"
size_hint: 0.4, 0.1
pos_hint: {"x": 0.3, "top": 0.4}
on_release: root.login()
Button:
text: "Don't have an account? Create one!"
size_hint: 0.35, 0.05
pos_hint: {"x": 0.325, "top": 0.1}
on_release:\
app.root.current = "create account"
root.create_btn()
<VotingWindow>:
name: "voting"
FloatLayout:
Button:
pos_hint: {"x": 0.1, "top": 0.9}
text: "Insert story about company here"
size_hint: 0.8, 0.4
Button:
text: "Yes"
size_hint: 0.3, 0.2
pos_hint: {"x": 0.1, "top": 0.4}
on_press: root.yes_btn()
Button:
text: "No"
size_hint: 0.3, 0.2
pos_hint: {"x": 0.6, "top": 0.4}
on_press: root.no_btn()
Button:
text: "Logout"
size_hint: 0.8, 0.1
pos_hint: {"x": 0.1, "top": 0.15}
on_release: app.root.current = "login"
<CreateAccountWindow>:
name: "create account"
email: email
password: password
FloatLayout:
FloatLayout:
Label:
text: "Create an account"
size_hint: 0.4, 0.1
pos_hint: {"x": 0.3, "top": 0.9}
Label:
text: "Email: "
size_hint: 0.1, 0.1
pos_hint: {"x": 0.2, "top": 0.7}
TextInput:
id: email
multiline: False
size_hint: 0.4, 0.1
pos_hint: {"x": 0.4, "top": 0.7}
Label:
text: "Password: "
size_hint: 0.1, 0.1
pos_hint: {"x": 0.2, "top": 0.6}
TextInput:
id: password
multiline: False
size_hint: 0.4, 0.1
pos_hint: {"x": 0.4, "top": 0.6}
Button:
text: "Create Account"
size_hint: 0.4, 0.1
pos_hint: {"x": 0.3, "top": 0.3}
on_release: \
app.root.current = "login"
root.create_btn()