[英]Kivy AttributeError: 'NoneType' object has no attribute 'current'
I'm new to Kivy and I'd really appreciate some help.我是 Kivy 的新手,非常感谢一些帮助。 I'm trying to make the button 'Manage Residents' switch screens but it comes up with the error:我正在尝试使“管理居民”按钮切换屏幕,但出现错误:
self.manager.current = 'manageResidents'
AttributeError: 'NoneType' object has no attribute 'current''
Here is my code:这是我的代码:
import sqlite3
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.dropdown import DropDown
from kivy.base import runTouchApp
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.textinput import TextInput
from kivy.properties import ObjectProperty
class mainMenu(Screen):
def __init__(self, **kwargs):
super(mainMenu, self).__init__(**kwargs)
# Selects the first name and last name of all residents and sorts by ascending order
db = sqlite3.connect("mainDatabase.db")
cursor = db.cursor()
dropDownValues = cursor.execute("SELECT firstName, lastName FROM residents ORDER BY firstName ASC").fetchall()
db.close()
mainDropdown = DropDown()#Assigns the variable mainDropdown to be a dropdown menu
This is the button that should change the screen这是应该改变屏幕的按钮
btn = Button(text="Manage Residents", size_hint_y=None, height=44)#Creates a button at the top of the dropdown menu that switches to manage residents screen
btn.bind(on_release=lambda btn: mainDropdown.select(btn.text))
btn.bind(on_release=self.changer)
Rest of code: Rest 代码:
mainDropdown.add_widget(btn)
mainButton = Button(text='Residents', size_hint=(0.25, 0.1))#Sets the name of the dropdown button, sizes it and makes it change its text to what the user has clicked on
mainButton.bind(on_release=mainDropdown.open)
runTouchApp(mainButton)
def changer(self,*args):
self.manager.current = 'manageResidents'
class manageResidents(Screen):
def __init__(self, **kwargs):
super(manageResidents, self).__init__(**kwargs)
my_label1 = Label(text="You are now on manage residents screen", font_size='24dp')
class MyApp(App):
def build(self):
my_screenmanager = ScreenManager()
screen1 = mainMenu(name='Main Menu')
screen2 = manageResidents(name='Manage Residents')
my_screenmanager.add_widget(screen1)
my_screenmanager.add_widget(screen2)
return my_screenmanager
if __name__ == "__main__":
MyApp().run()here
There are two problems in your application.您的应用程序中有两个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.