从弹出式窗口中创建的标签中获取弹出式窗口中显示的方法的文本时遇到问题。我所有的标签,按钮,布局...等都是不同的类,因此我不知道这是计时问题还是实例问题,但我希望弹出窗口显示标签中的文本。我有一个计算逻辑的按钮,然后以相同的方法显示所有弹出窗口。如果直接在kv文件OutputLabel中的标签下面添加文本,我可以得到显示的文本:text:“ whatever”,但是如果我只是尝试在类中引用标签并使标签的text属性成为输出,则无法显示文本。
Main.py(最后,我已经创建了输出标签和弹出窗口) Calculate(Button)类:
class Calculate(Button):
#main program
def calculate(self):
#make inputs into numbers
goal = float(self.goal.text)
save = float(self.save.text)
savei = float(self.savei.text) / 100
repeat = float(self.repeat.text)
syears = int(self.syears.text)
smonths = int(self.smonths.text)
#get current compound toggle
compound = 0
if self.daily.state == 'down':
compound = 365
elif self.monthly.state == 'down':
compound = 12
elif self.yearly.state == 'down':
compound = 1
#get current repeat deposit toggle
repDep = 0
if self.none.state == 'down':
repDep = 0
elif self.week.state == 'down':
repDep = 7
elif self.biweek.state == 'down':
repDep = 14
elif self.month2.state == 'down':
repDep = 30.417
elif self.year2.state == 'down':
repDep = 365
#variables for program
totalDays = syears*365 + smonths*30.417
interestRate = savei/compound
totalMoney = 0
count = 0
day = 0
repDay = 0
counter = 0
#program begin
while totalDays > 0:
if count < 1:
totalMoney = save
totalDays -= 1
count += 1
totalDays -= 1
if compound == 365:
totalMoney *= (interestRate * repDep + 1)
totalDays -= 1
elif compound == 12:
if day >= 30:
totalMoney *= (interestRate * repDep + 1)
day = 0
totalDays -= 1
else:
day += 1
totalDays -= 1
elif compound == 1:
if day == 365:
totalMoney *= (interestRate * repDep + 1)
day = 0
totalDays -= 1
else:
day += 1
totalDays -= 1
if repDay >= repDep:
totalMoney += repeat
repDay = 0
else:
repDay += 1
#final output string
total = str(totalMoney)
#totals popup screen
out = OutputLabel()
show = TotalPopup()
popupWindow = Popup(title="TOTALS", content=show, size_hint=(.8,.8))
# Create the popup window
out.text = total
popupWindow.open() # show the popup
pass
Layout.kv(定义弹出式布局。如果我在此处显示文本:“ whatever”,则显示该文本,但是其他任何内容表示我的输出的属性与我的outputlabel.text都为nonetype)
<TotalPopup>:
GridLayout:
cols:1
OutputLabel:
GoalOutputLabel:
NoReinvestLabel:
OutputLabel
OutputLabel(Label)类: 通过
否则,它将立即运行,不会在弹出窗口中显示标签中的文本。
答案 0 :(得分:0)
没关系...我想出了其他办法。刚刚在弹出创建代码中写了标签。但是,如果有办法,我仍然想知道怎么做而不必这样做。