我有两个文件:
test.py
和test.kv
。当我从.kv
文件中调用insert_update_account()
函数时,会出现错误:File "kivy/weakproxy.pyx", line 30, in kivy.weakproxy.WeakProxy.__getattr__ (kivy/weakproxy.c:1144)
File "kivy/weakproxy.pyx", line 26, in kivy.weakproxy.WeakProxy.__ref__ (kivy/weakproxy.c:1043)
ReferenceError: weakly-referenced object no longer exists<br/>
如果我在insert_update_account()
函数中注释掉self.display_account()
这一行,则不会出现错误。
test.py
import kivy
kivy.require('1.9.0') # replace with your current kivy version !
import sqlite3 as lite
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import BooleanProperty, ListProperty, StringProperty, ObjectProperty, NumericProperty
from kivy.lang import Builder
from kivy.core.window import Window
Window.maximize()
con = lite.connect('test.db')
#con = lite.connect(path + 'fact.db')
con.text_factory = str
cur = con.cursor()
class MainMenu(BoxLayout):
def display_account(self):
self.dropdown.dismiss()
self.remove_widgets()
self.rvaccount = TEST()
self.content_area.add_widget(self.rvaccount)
self.cur.close()
self.con.close()
def insert_update_account(self, obj):
cur.execute("UPDATE table SET test1=?, test2=? WHERE test3=?",
(obj.col_data[1], obj.col_data[2], obj.col_data[0]))
con.commit()
self.display_account()
class TEST(BoxLayout):
data_items = ListProperty([])
col1 = ListProperty()
col2 = ListProperty()
mode = StringProperty("")
def __init__(self, **kwargs):
super(TEST, self).__init__(**kwargs)
self.get_data()
def update(self):
self.col1 = [{'test1': str(x[0]), 'test2': str(x[1]), 'key': 'test1'} for x in self.data_items]
self.col2 = [{'test1': str(x[0]), 'test2': str(x[1]), 'key': 'test2'} for x in self.data_items]
def get_data(self):
cur.execute("SELECT * from table")
rows = cur.fetchall()
print(rows)
i = 0
for row in rows:
self.data_items_city.append([row[0], row[1], i])
i += 1
print(self.data_items_city)
self.update()
class TestApp(App):
title = "test"
def build(self):
self.root = Builder.load_file('test.kv')
return MainMenu()
if __name__ == '__main__':
TestApp().run()
有人能帮我吗?
close()
,另外,在你的类中__init__
方法在哪里呢? - ddor254