所以我的 python 文件中有一个类,我想从主 python 文件中分离出来,因为我需要修改它几次并在主文件中使用它。但是,由于该类需要访问 kivy 文件来读取 id,因此我无法在不加载 kv 文件两次的情况下将该类与主类分开,这会使一切都搞砸了。我怎样才能基本上使这个类可导入?
class RightSide(BoxLayout):
order_size = []
overlay = StringProperty('Current Order will be displayed here')
tabname = parameter_length
iterator = 0
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.orientation = 'vertical'
for i in range(len(menu)):
self.add_widget(Skeleton())
def tally(self):
global OID
order_size = self.order_size
print(OID)
OID = OID + 1
print(OID)
rightside = kv.ids.one.two.three.newlay.rightside
for skel in rightside.children:
if isinstance(skel, Skeleton):
if self.iterator > len(menu)-1:
self.iterator = 0
order_size.clear()
self.tabname[self.iterator] = skel.drink_name, skel.ids.label_id.text
self.iterator = self.iterator + 1
order_size.insert(0, skel.ids.label_id.text)
order_size.insert(0, OID)
self.tabname.reverse()
self.tabname.insert(0, OID)
makeitastring = ''.join(map(str, self.tabname))
self.overlay = makeitastring
con = sql.connect(host='xxxxxx', user='root', password='xxxxxxx.', database='new_schema')
cur = con.cursor()
cur.execute(query, order_size)
con.commit()
con.close()
def clean(self):
rightside = kv.ids.one.two.three.newlay.rightside
for skel in rightside.children:
if isinstance(skel, Skeleton):
skel.ids.label_id.text = '0'
skel.count = 0
kv = Builder.load_file("b.kv")