我目前正在构建一个将Excel工作表转换为JSON格式的小程序。我希望每次进行更改或更新时,excel文件都使用进行更改的人的登录名和日期信息进行更新。 我使用KivyMD创建了两个屏幕,一个屏幕用于登录数据,另一个屏幕用于excel功能。我当前的问题是我想从上一个屏幕获取登录信息,但是我很难理解如何获取数据。 我尝试使用在上一篇文章中找到的以下行,在“更新”屏幕中创建一个“登录”变量,该变量引用“日志”屏幕中的ID:“ 登录= self.manager.screens [1]” .ids.login.text ”
但是该行给我以下错误:“
登录= self.manager.screens [1] .ids.login.text
在kivy.properties.ObservableDict中,文件863行的“ kivy \ properties.pyx”。 getattr
AttributeError:“超级”对象没有属性“ getattr ”
“
我是KivyMD的新手,我很确定这里没有看到或遗失的东西。我将不胜感激。
这是我的.py文件:
results[which.max(as.numeric(do.call(rbind, results)[,2]))]
#[[1]]
#[1] "Value3" "20"
这是我的.kv文件:
import os.path
from kivymd.app import MDApp
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.lang import Builder
from kivymd.uix.button import MDFlatButton
from kivymd.uix.dialog import MDDialog
from helpers import screen_helper_2
from kivy.core.window import Window
from datetime import datetime
import json
import functions as function
Window.size = (400, 500)
# AlbacoreLog Screen Fully Functional
class AlbacoreLogScreen(Screen):
def show_login(self, *args):
close_button = MDFlatButton(text='Close', on_release=self.close_dialog)
if self.ids.login.text is "":
check_string = 'Please enter Login or Name'
self.dialog = MDDialog(text=check_string,
size_hint=(0.7, 1),
buttons=[close_button])
self.dialog.open()
else:
self.manager.current = 'function'
def close_dialog(self, obj):
self.dialog.dismiss()
class AutoUpdateScreen(Screen):
def albacorize_update(self, *args):
def close_ext(*args):
dialog_ext.dismiss()
def close_ext_2(*args):
dialog_5.dismiss()
def close_update(*args):
dialog_update.dismiss()
close_button_ext_2 = MDFlatButton(text='Close', on_release=close_ext_2)
close_button_ext = MDFlatButton(text='Close', on_release=close_ext)
close_button_update = MDFlatButton(text='Close', on_release=close_update)
if self.ids.change.text is "":
dialog_update = MDDialog(text='Also, make sure to add your update',
size_hint=(0.7, 1),
buttons=[close_button_update])
dialog_update.open()
self.back_to_update()
if self.ids.ms.text is "":
dialog_ext = MDDialog(text='Please enter Master Sheet name and extension',
size_hint=(0.7, 1),
buttons=[close_button_ext])
dialog_ext.open()
self.back_to_update()
elif type(self.ids.ms.text) is str:
ms = self.ids.ms.text
update = self.ids.change.text
if os.path.isfile(ms):
login = self.manager.screens[1].ids.login.text
now = datetime.now()
time_date = now.strftime("%d/%m/%Y %H:%M:%S")
print("File exist")
q_and_a_section = function.question_answer_build(ms)
node_section = function.section_build(ms)
function.updates(ms, login, time_date, update) ##I want to pass the login data to a different module on my program in order to build the new excel sheet.
else:
print("File not exist")
dialog_5 = MDDialog(text='MS does not have extension or is not in current root folder',
size_hint=(0.7, 1),
buttons=[close_button_ext_2])
dialog_5.open()
self.manager.current = 'msautomap'
def back_to_function(self, *args):
self.manager.current = 'function'
def back_to_update(self, *args):
self.manager.current = 'msautoupdate'
sm = ScreenManager()
sm.add_widget(AlbacoreLogScreen(name='log'))
sm.add_widget(AutoUpdateScreen(name='msautoupdate'))
class AlbacorizerApp(MDApp):
def build(self):
self.theme_cls.primary_palette = "Yellow"
self.theme_cls.primary_hue = "A700"
self.theme_cls.theme_style = "Dark"
screen = Builder.load_string(screen_helper_2)
return screen
AlbacorizerApp().run()
答案 0 :(得分:0)
尝试更改:
login = self.manager.screens[1].ids.login.text
收件人:
login = self.manager.get_screen('log').ids.login.text
使用self.manager.screens[1]
会使代码取决于Screens
列表中screens
的顺序(而[1]
是错误的)。使用get_screen('log')
使您的代码独立于Screens
的顺序(并获得正确的代码)。