1 回答
TA贡献1883条经验 获得超3个赞
screen_output_label不是类的参数,而是小部件的 id,所以那行
SyllOutputPopup.screen_output_label.text = cfd_syll.tabulate()
是错误的,你应该使用:
SyllOutputPopup.ids.screen_output_label.text = cfd_syll.tabulate()
==========
此外,您正在创建SyllOutputPopup类的几个对象。将文本放在一个对象中:
try: SyllOutputPopup.ids.screen_output_label.text = cfd_syll.tabulate()
然后你创建一个新对象,它是空白的,有空的 Label,并显示它:
show = SyllOutputPopup() # Create a new instance
SyllOutputPopupWindow = Popup(title="Output", content=show, size_hint=(None,None),size=(600,400))
SyllOutputPopupWindow.open()
您应该使用一个对象 - 将文本设置在那里,然后准确地显示该对象,如下所示:
def output_toscreen(сorpus_root, *args):
corpus = PlaintextCorpusReader(args[0], '.*')
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()])
# that will be your object
self.sylloutputpopup = SyllOutputPopup()
self.sylloutputpopup.ids.screen_output_label.text = cfd_syll.tabulate()
show_syllsoutput_popup() # run the popup
def show_syllsoutput_popup():
show = self.sylloutputpopup
SyllOutputPopupWindow = Popup(title="Output", content=show, size_hint=(None,None),size=(600,400))
SyllOutputPopupWindow.open()
但只有当上面的两个函数都在同一类中时,这才有效。
添加回答
举报