Я добавил флажок на экране входа в систему для сохранения имени пользователя и пароля, чтобы пользователю не приходилось вводить их каждый раз. Я думал о создании текстового файла, который будет хранить эту информацию, но, возможно, есть лучший подход. Я не могу сохранить его правильно; это то, что я до сих пор. В методе init моего класса я проверяю, есть ли текстовый файл с информацией. Если это так, я хочу извлечь имя пользователя и пароль, чтобы заполнить TextInputs на моем экране. Если нет, я оставлю их пустыми и позволю пользователю заполнить два TextInputs. Текстовые входы решаются в моем следующем методе add_user (). Я получаю эту ошибку: AttributeError: 'super' object has no attribute '__getattr__'
. Я не выяснил поведение флажка, так как у меня уже есть ошибка. У кого-нибудь есть идея?
try.py
class SigninWindows(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
if os.path.isfile('prev_details.txt'):
with open('prev_details.txt', 'r') as f:
d = f.read().split(',')
self.ids.username_field.text = d[0]
self.ids.pwd_field.text = d[1]
else:
self.ids.username_field.text = ''
self.ids.pwd_field.text = ''
def add_user(self):
uname = self.ids.username_field.text
passw = self.ids.pwd_field.text
info = self.ids.info
table_name = uname.replace('@', '_').replace('.', '_')
try.kv
<SigninWindows>:
id: signin_page
name: "signin_page"
orientation: "vertical"
spacing: 10
space_x: self.size[0]/5.5
canvas.before:
Color:
rgba: (0,0,0,1)
Rectangle:
size: self.size
pos: self.pos
BoxLayout:
id: data_signin
orientation: 'vertical'
size_hint_x: 1
BoxLayout:
Image:
id: ds_im
orientation: 'vertical'
source: 'ds.png'
allow_stretch: True
BoxLayout:
id: validate_info
orientation: "vertical"
size_hint: 1,0.8
padding: 80, 10
Label:
id: info
text: ''
markup: True
TextInput:
id: username_field
text: ''
hint_text: "Username"
hint_text_color: 0.5,0.5,0.5,1
multiline: False
focus: True
on_text_validate: pwd_field.focus = True
size_hint: 1, .8
foreground_color: 0.5,0.5,0.5,1
background_color: .1,.1,.1,1
write_tab: False
TextInput:
id: pwd_field
text: ''
hint_text: "Password"
hint_text_color: 0.5,0.5,0.5,1
multiline: False
password: True
on_text_validate: root.validate_user()
size_hint: 1,0.8
foreground_color: 0.5,0.5,0.5,1
background_color: .1,.1,.1,1
BoxLayout:
id: remember_section
orientation : 'horizontal'
size_hint_x: None
width: 80
size_hint_y: None
height: 50
padding: 80, 10
CheckBox:
text: ''
size_hint_x: None
width: 25
size_hint_y: None
height: 25
canvas.before:
Color:
rgba: (1, 1, 1, 1)
Rectangle:
size: self.size
pos: self.pos
Label:
text: 'Remember User id?'
font_size: 20
size_hint_x: None
width: 220