I try to bind a function (in .py) to button (in kv.) after directory selection with Filechooser (all at one Screen) as follows:
.py:
class SyllWindow(Screen): #screen where all happens
def select(self, *args):
if args[1]:
filepath = args[1][0]
try: self.label.text = filepath
except: pass
def output_csv(corpus_root): #function
corpus = PlaintextCorpusReader(corpus_root, '.*') #this must be irrelevant actually
def reduce_dip(corpus_string):
corpus_string = corpus_string.replace("Ei", "ö")
corpus_string = corpus_string.replace("ei", "ö")
# reduced
corpus_string = corpus_string.replace("ie", "ö")
return corpus_string
vowels = [' ','a','e','i','o','u','ä','ö','ü','A','E','I','O','U','Ä','Ö','Ü']
cfd_syll = nltk.ConditionalFreqDist(
(textname, num_syll)
for textname in corpus.fileids()
for num_syll in [len(w) for w in ''.join(char for char in reduce_dip(corpus.raw(fileids=textname)) if char in vowels).split()])
syll_dataframe = DataFrame(cfd_syll)
return syll_dataframe.to_csv(path + '\silben.csv')
pass
.kv (button block):
Button:
text: '.csv'
font_size: 14
on_release: self.output_csv(self.filepath)
Looks like this:
After pressing ".csv" I get an error AttributeError: 'Button' object has no attribute 'output_csv'
I'm aware of similar issues described here, here and here, but all examples there are in Python language, while my issue seems to be more about Kivy language.
I'd be grateful for any advice.
Full error traceback:
File "C:\Users\gavrk\AppData\Local\Programs\Python\Python37-32\Lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\gavrk\AppData\Local\Programs\Python\Python37-32\Lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\GUI Projects\gercort\main.py", line 147, in <module>
Gercort().run()
File "C:\Users\gavrk\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\kivy\app.py", line 855, in run
runTouchApp()
File "C:\Users\gavrk\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\kivy\base.py", line 504, in runTouchApp
EventLoop.window.mainloop()
File "C:\Users\gavrk\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\kivy\core\window\window_sdl2.py", line 747, in mainloop
self._mainloop()
File "C:\Users\gavrk\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\kivy\core\window\window_sdl2.py", line 479, in _mainloop
EventLoop.idle()
File "C:\Users\gavrk\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\kivy\base.py", line 342, in idle
self.dispatch_input()
File "C:\Users\gavrk\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\kivy\base.py", line 327, in dispatch_input
post_dispatch_input(*pop(0))
File "C:\Users\gavrk\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\kivy\base.py", line 293, in post_dispatch_input
wid.dispatch('on_touch_up', me)
File "C:\Users\gavrk\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\kivy\_event.cp37-win32.pyd", line 707, in kivy._event.EventDispatcher.dispatch
File "C:\Users\gavrk\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\kivy\uix\behaviors\button.py", line 179, in on_touch_up
self.dispatch('on_release')
File "C:\Users\gavrk\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\kivy\_event.cp37-win32.pyd", line 703, in kivy._event.EventDispatcher.dispatch
File "C:\Users\gavrk\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\kivy\_event.cp37-win32.pyd", line 1214, in kivy._event.EventObservers.dispatch
File "C:\Users\gavrk\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\kivy\_event.cp37-win32.pyd", line 1098, in kivy._event.EventObservers._dispatch
File "C:\Users\gavrk\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\kivy\lang\builder.py", line 64, in custom_callback
exec(__kvlang__.co_value, idmap)
File "C:\GUI Projects\gercort\gercort.kv", line 489, in <module>
on_release: self.output_csv(self.filepath2)
File "C:\Users\gavrk\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\kivy\weakproxy.cp37-win32.pyd", line 32, in kivy.weakproxy.WeakProxy.__getattr__
builtins.AttributeError: 'Button' object has no attribute 'output_csv'