python - TypeError:“NoneType”对象不可下标 Python Kivymd 和 MySql
问题描述
所以一切正常,值被添加到数据库中,但由于某种原因,它在给出以下错误后直接失败 -
TypeError: 'NoneType' object is not subscriptable
我虽然可能是我在屏幕上显示它的方式,所以我删除了最后一点,看看它是否会顺利通过,但它仍然会产生同样的错误,尽我所能,但我的大脑一片空白,我得去睡觉了,任何帮助表示赞赏,迟来的复活节快乐!
Python代码 -
def add_student_now(self):
spec_email = self.manager_screen.home.nav_drawer.grid_drawer.drawer_email.text
student_first_name = self.manager_screen.add_student.firstname.text
student_last_name = self.manager_screen.add_student.lastname.text
student_notes = self.manager_screen.add_student.notes.text
con = sql.connect(host="localhost", user="root", password="hipeople11", database="people")
cur = con.cursor(buffered=True)
query = "SELECT email, first_name, surname FROM teachers"
cur.execute(query)
for (email, first_name, surname) in cur:
if email == spec_email:
full_name = first_name.lower() + surname.lower()
print(full_name)
print(spec_email)
print("{}students".format(full_name))
cur.execute("INSERT INTO {}students (studentfirstname, studentlastname, studentnotes) VALUES (%s,%s,%s)".format(full_name), (student_first_name, student_last_name, student_notes))
con.commit()
con.close()
self.manager_screen.current = "home"
student = student_first_name + " " + student_last_name
#create label
self.manager_screen.home.grid_home.s_home.h_student_list.add_widget(OneLineListItem(text=student)) ```
Kivy code-
MDScreen:
id: home
name: "home"
radius: [25, 0, 0, 0]
grid_home: grid_home
nav_drawer: nav_drawer
MDGridLayout:
id: grid_home
h_toolbar : h_toolbar
s_home: s_home
ab_home: ab_home
del_home: del_home
cols: 1
rows: 2
MDToolbar:
id: h_toolbar
title: "NewArk Grading Systems"
pos_hint: {'top':1.0}
md_bg_color: 0,0,0,1
elevation: 10
left_action_items: [["menu", lambda x: nav_drawer.set_state("open")]]
ScrollView:
id: s_home
name: "s_home"
h_student_list: h_student_list
do_scroll_x: False
MDList:
id: h_student_list
MDScreen:
id: add_student
name: "add_student"
firstname: firstname
lastname: lastname
notes: notes
radius: [25, 0, 0, 0]
MDFloatLayout:
MDLabel:
text:'Enter Details'
pos_hint: {'center_x': 0.965, 'center_y':0.6}
bold: True
MDRectangleFlatButton:
text: 'Add Student'
pos_hint: {'center_x':0.5, 'center_y': 0.2}
line_color: 0,0,0,1
text_color: 0,0,0,1
on_release: root.add_student_now()
MDTextField:
id: firstname
hint_text: 'First Name'
pos_hint: {'center_x':0.5, 'center_y': 0.5}
icon_right: 'smile'
color_mode: 'custom'
helper_text_mode: "on_focus"
line_color_focus: 0, 0, 0, 1
size_hint_x:None
MDTextField:
id: lastname
hint_text: 'Last Name'
pos_hint: {'center_x':0.5, 'center_y': 0.4}
icon_right: 'smile'
color_mode: 'custom'
helper_text_mode: "on_focus"
line_color_focus: 0, 0, 0, 1
size_hint_x:None
MDTextField:
id: notes
hint_text: 'Notes'
pos_hint: {'center_x':0.5, 'center_y': 0.3}
icon_right: 'smile'
color_mode: 'custom'
helper_text_mode: "on_focus"
line_color_focus: 0, 0, 0, 1
size_hint_x:None
multiline : True
解决方案
推荐阅读
- django - 我找不到姜戈
- python-3.x - 如何构建 Python3 项目以运行 Web 服务和运行测试套件(导入问题)
- r - 使用 knitr 在 Rmarkdown 中创建 PDF 文件时分辨率低且文本模糊?
- python-3.x - 使用 crontab 应该在启动时运行的 3 个 python 程序中的一个不会
- c# - SSIS:调用目标已引发错误异常
- r - 拆分字符串、标记子字符串并将标记转换为数字向量
- serial-port - 在 arduino ide 上为 ESP32 Dev 选择 com 端口
- ruby-on-rails - Rails 在更新时忽略参数
- algorithm - 是否有一种算法来检测一条线和 Catmull-Clark 细分曲面之间的交点?
- c# - 当仍然引用它的对象字段时,C# 对象有资格进行垃圾回收吗?