我正在使用python-2.7
和kivy
。我有一个文件test.py
有人可以告诉我如何从def abc(self):
拨打def update(self):
吗?
现在我使用Invoice().abc()
进行通话,然后打印calling
但不显示label
和value
from kivy.uix.label import Label
from kivy.uix.screenmanager import Screen
from kivy.app import App
from kivy.core.window import Window
from functools import partial
from kivy.uix.popup import Popup
from kivy.properties import BooleanProperty, ListProperty, StringProperty, ObjectProperty, NumericProperty
Window.clearcolor = (0.5, 0.5, 0.5, 1)
Window.size = (600, 600)
class MyLabel(Label):
pass
class check(Popup):
mode = StringProperty("")
col_data = ListProperty(["?"])
def __init__(self, obj, **kwargs):
super(check, self).__init__(**kwargs)
if obj.mode == "Update":
cur.execute("select `column` from `table_name` where `id`=?",(edit_id,))
row = cur.fetchone()
self.col_data[1] = row[0]
def update(self):
#do some stuff after call abc function
Invoice().abc()
class Invoice(Screen):
def __init__(self, **kwargs):
super(Invoice, self).__init__(**kwargs)
def abc(self):
print('calling')
#fetching from database
arr = [(11, 'Item1', '1001'), (12, 'Item2', '2001'), (13, 'Item3', '102')]
layout = self.ids['invoices']
for row in arr:
layout.add_widget(MyLabel(text=str('[ref=world]' + row[1]) + '[/ref]',
size_hint_x=.35,
halign='left',
markup=True,
on_ref_press=partial(self.open_form, row[0])))
def open_form(self, id, *args):
global edit_id
edit_id = id
self.mode = "Update"
check(self)
答案 0 :(得分:0)
您似乎永远不会在build
中运行Test
函数来创建Invoice
的实例。尝试使用此代码作为主要功能。第一行设置x
等于Test().build()
返回的数据Invoice()
,从而为x提供Invoice
类的属性。
if __name__ == '__main__':
x=Test().build()
x.abc()
下一位将回答如何从其他班级调用abc()
的问题。您可以将update
功能更改为:
def update(self):
#do some stuff after call abc function
x=Invoice()
x.abc()
您首先需要按x=Invoice()
构建课程,然后您可以使用此格式调用Invoice
内的函数x.abc()