Kivy AttributeError:'NoneType'对象没有属性'current'

时间:2020-08-01 11:39:11

标签: python kivy

我是Kivy的新手,非常感谢您的帮助。我正在尝试使按钮“管理居民”切换屏幕,但出现错误:

// Draw a sine
var chartValues = new ChartValues<Point>();
for (int x = 0; x < 361; x++)
{
  var point = new Point() {X = x, Y = Math.Sin(x * Math.PI / 180)};
  chartValues.Add(point);
}

this.SeriesCollection = new SeriesCollection
{
  // Set the line series color directly on the series object
  new LineSeries
  {
    Title = "Yellow Series",
    Values = chartValues,
    Fill = Brushes.Yellow,
    Stroke = Brushes.Blue
  },
  // Or use a Mapper which offers more flexibility e.g. allowing conditional coloring
  new LineSeries
  {
    Title = "Mixed Color Series",
    Configuration = new CartesianMapper<Point>()
      .X(point => point.X)
      .Y(point => point.Y)
      .Stroke(point => point.X > 50 ? Brushes.Red : Brushes.LightGreen)
      .Fill(point => point.X > 50 ? Brushes.Red : Brushes.LightGreen),
    Values = chartValues
  }
};

这是我的代码:

const file = [
  {
    name: "same",
    hobby: '{ "name": "music", "type": "jazz" }'
  },
];

let dd = []

file.forEach(
  (it)=>{
    let val = JSON.parse(it.hobby)
    Object.keys(val).map(hby=>
     {
      
      dd.push({
        name:it.name,
        content:it.hobby,
        content1:`h_${hby}`,
        constent2:val[hby]
        })
    }
  )})

console.log(dd)

这是应该更改屏幕的按钮

self.manager.current = 'manageResidents'
AttributeError: 'NoneType' object has no attribute 'current''

其余代码:

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

1 个答案:

答案 0 :(得分:0)

问题

您的应用程序中有两个问题。

  1. 在您的应用中,它正在运行 runTouchApp(mainButton)。因此,没有属性'current'
  2. 没有'manageResidents'
  3. 的屏幕名称

解决方案

  1. self.add_widget(mainButton)
  2. 替换 runTouchApp(mainButton)
  3. 'ManageResidents'
  4. 替换'manageResidents'