Я пытаюсь привязать функцию (в .py) к кнопке (в кв.) После выбора каталога с помощью Filechooser (все на одном экране) следующим образом:
.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:
text: '.csv'
font_size: 14
on_release: self.output_csv(self.filepath)
Выглядит так:
После нажатия «.csv» Я получаю сообщение об ошибке AttributeError: 'Button' object has no attribute 'output_csv'
Мне известны подобные проблемы, описанные здесь , здесь и здесь , но все примеры приведены на языке Python, в то время как моя проблема, кажется, больше связана с языком Kivy.
Буду признателен за любой совет.
Полная трассировка ошибок:
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'