python - 在弹出窗口中将文本输出到 kivy 标签
问题描述
我在从弹出窗口中显示的方法从弹出窗口中创建的标签中获取文本时遇到问题。我所有的标签、按钮、布局......等都是不同的类,所以我不知道这是时间问题还是实例问题,但我希望弹出窗口显示标签中的文本。我有一个计算逻辑的按钮,然后以相同的方法显示弹出窗口。如果我直接在我的 kv 文件 OutputLabel: text: "whatever" 的标签下方添加,我可以让文本出现,但如果我只是尝试在类中引用标签并将标签的 text 属性作为输出,我就不能。
Main.py(最后,我已经创建了输出标签和弹出窗口)类计算(按钮):
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 来说是非类型)
<TotalPopup>:
GridLayout:
cols:1
OutputLabel:
GoalOutputLabel:
NoReinvestLabel:
输出标签
类输出标签(标签):通过
否则,它现在可以正常运行,只是不会在弹出窗口中显示标签中的文本。
解决方案
没关系...我想出了别的办法。只是在弹出创建代码中写了标签。但是,如果有办法,我仍然想知道如何做到这一点而不必这样做。
推荐阅读
- docker - Jenkins 和 Kubernetes 在同一个虚拟机中
- php - 在多行或多个值中查看一列的逗号分隔值
- jsx - 如何编译不使用子代的 Reason JSX 函数
- protractor - 拥有将在一个位置的每次测试之前运行的代码
- android - 无法从 build.gradle 更新 Android Studio for mac 中的版本代码
- javascript - D3 mousedown 事件删除错误的节点
- javascript - 参数未传递到 TabNavigator 中的子屏幕
- debugging - 如何消除全局变量
- android - 当多个用户使用同一设备访问同一应用程序时如何处理 Firebase 注册 ID(令牌)
- ruby-on-rails - 如何创建一个选择字段,在 Rails 中动态加载元素以实现多对多关联?