struggling with python and Kivy -
i'm learning python , kivy , i'm struggling understand how call functions , continue functions kivy gui.
here .py:
import csv import os import easygui import kivy kivy.require('1.0.7') kivy.app import app kivy.animation import animation kivy.uix.button import button kivy.uix.label import label kivy.uix.gridlayout import gridlayout kivy.uix.textinput import textinput def csvimport(filename): open(filename, 'rb') f: reader = csv.reader(f) your_list = list(reader) return your_list class loadfile(app): def fileloadscreen(self): self.add_widget(button(size_hint_y=(none), height=('48dp'), text='select file', on_press=self.importfile)) def importfile(self, instance): filepath = easygui.fileopenbox() if filepath!='.': a=csvimport(filepath) instance.text='file loaded' instance.disabled=true class loginbakapp(app): def logauth(username,password): if username!='' , password!='': print('ok') kv_directory = 'gui' if __name__ == '__main__': loginbakapp().run()
and loginbak.kv:
#:kivy 1.9.0 gridlayout: row_force_default: true row_default_height: 40 rows: 3 cols: 2 padding: 10 spacing: 10 label: id: userlabel text: 'username:' textinput: id: username label: id: passwordlabel text: 'password:' textinput: id: password password: true button: id:btn_login text: 'login' on_press: print('ok')
this code seems work without issues (when click login button, print 'ok'. tried swap out
on_press: logauth(username,password)
and error logauth not defined.
ultimately, i'm trying model here (as first learning experience) hit login button , long fields not blank, display login success message 5 seconds , delete fields , call loadfile app (add button can clicked select , import file).
what doing wrong here? i've sifted through 60 scripts online , have been looking @ kivy examples hours , cannot figure out how i'm doing wrong. can point me in right direction and/or make suggestions creating/deleting gui described? i'm new kivy (and can code basic python scripts) little confusing when read of other questions on stackoverflow.
on_press: logauth(username,password)
logauth method of app class, not function defined in kv namespace. can instead use app.logauth(...)
, app
keyword references current app instance.
Comments
Post a Comment