简体   繁体   English

Kivy AttributeError: 'NoneType' object 没有属性 'current'

[英]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

Problem问题

There are two problems in your application.您的应用程序中有两个问题。

  1. In your app, it is running runTouchApp(mainButton) .在您的应用程序中,它正在运行runTouchApp(mainButton) Therefore, there is no attribute, 'current'因此,没有属性“当前”
  2. There is no screen name of 'manageResidents'没有“manageResidents”的网

Solution解决方案

  1. Replace runTouchApp(mainButton) with self.add_widget(mainButton)runTouchApp(mainButton)替换为self.add_widget(mainButton)
  2. Replace 'manageResidents' with 'ManageResidents'“manageResidents”替换为“ManageResidents”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError:'NoneType'对象没有属性'text'kivy - AttributeError: 'NoneType' object has no attribute 'text' kivy Kivy AttributeError: 'NoneType' object 没有属性 'ids' - Kivy AttributeError: 'NoneType' object has no attribute 'ids' AttributeError: 'NoneType' 对象没有属性 'current' - AttributeError: 'NoneType' object has no attribute 'current' Python Kivy AttributeError: 'NoneType' 对象没有属性 'bind' - Python Kivy AttributeError: 'NoneType' object has no attribute 'bind' Kivy AttributeError: 'NoneType' 对象没有属性 'get_screen' - Kivy AttributeError: 'NoneType' object has no attribute 'get_screen' Kivy Scrollview: AttributeError: 'NoneType' 对象没有属性 'bind' - Kivy Scrollview: AttributeError: 'NoneType' object has no attribute 'bind' 使用 Kivy 切换屏幕:AttributeError: 'NoneType' object has no attribute 'transition' - Switching screens using Kivy: AttributeError: 'NoneType' object has no attribute 'transition' Kivy.exe 文件不工作 - AttributeError: 'NoneType' object 没有属性 'size' - Kivy .exe file not working - AttributeError: 'NoneType' object has no attribute 'size' Kivy Builder: AttributeError: 'NoneType' 对象没有属性 'text' - Kivy Buildozer: AttributeError: 'NoneType' object has no attribute 'text' Kivy:AttributeError:'NoneType' 对象没有属性 'add_widget' - Kivy: AttributeError: 'NoneType' object has no attribute 'add_widget'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM