python - tkinter NoneType 对象没有属性“配置”:无法更改标签文本
问题描述
我在 tkinter 中有一个界面,我在其中放置了一些标签、一个条目和一个按钮。因此,当我在条目中输入一个数字时,一些指标是在后台计算的,特别是self.controller.Configurazione.IncentivoServiceProvider
在 label 中self.incentivo_provider
。因此,当我在条目中输入一个数字并按下按钮时,我想更新所述标签中的文本,但我不断收到“NoneType”对象没有引用相同标签的属性“配置”。我尝试了各种解决方案,我什至尝试在 InputPercentaliEnergiaCondivisa 函数的范围内定义 UpdateLabel 函数,但我总是遇到同样的错误。任何人都可以帮助我吗?这是代码:
def SetPercentuale(self, valore):
print("premuto "+ str(valore))
self.controller.Configurazione.SetPercentualeRitenzione(100-valore)
def UpdateLabel(self, event):
print("Entro qua e percentuale ritenzione vale: "+str(self.controller.Configurazione.PercentualeRitenzione))
print("Entro qua e incentivo vale: "+str(self.controller.Configurazione.IncentivoServiceProvider))
self.incentivo_provider.config(text="L'ammontare destinato al service provider risulta: "+str(self.controller.Configurazione.IncentivoServiceProvider))
self.incentivo_provider.update()
def InputPercentualiEnergiaCondivisa(self):
self.PercentualeRitenzione = 0
tk.Label(self, text="Specificare la percentuale attribuibile agli utenti").pack()
self.percentuale_attribuibile = tk.Entry(self, textvariable=tk.IntVar())
self.percentuale_attribuibile.pack()
self.button = tk.Button(self, text="Valida")
self.button.bind("<Button-1>", lambda event: self.SetPercentuale(int(self.percentuale_attribuibile.get())))
self.button.bind("<Button-1>", self.UpdateLabel, add='+')
self.button.pack()
self.PercentualeRitenzione = 100 - int(self.percentuale_attribuibile.get())
#Istanzio la classe Configurazione che salva tutti i dati relativi alla configurazione
self.controller.Configurazione = Configurazione(len(self.controller.Proprietari_Impianti), len(self.controller.Proprietari_Superficie), len(self.controller.Consumatori_Semplici), len(self.controller.Finanziatori_Proprietari), len(self.controller.Finanziatori_Semplici), self.TotaleImmessa, self.TotalePrelevata, self.EnergiaCondivisa, self.PercentualeRitenzione)
self.incentivo_provider = tk.Label(self, text="L'ammontare destinato al service provider risulta: "+str(self.controller.Configurazione.IncentivoServiceProvider)).pack()
tk.Label(self, text="L'incentivo da ripartire agli utenti ammonta a: "+str(self.EnergiaCondivisa*(Parametri.IncentivoMise + Parametri.IncentivoArera)*int(self.percentuale_attribuibile.get()))).pack()
tk.Label(self, text="Specificare per ogni utente la percentuale dell'incentivo da attribuirgli. ").pack()
解决方案
在这一行 -
self.incentivo_provider = tk.Label(self, text="L'ammontare destinato al service provider risulta: "+str(self.controller.Configurazione.IncentivoServiceProvider)).pack()
您需要将其分隔.pack()
到下一行 -
self.incentivo_provider = tk.Label(self, text="L'ammontare destinato al service provider risulta: "+str(self.controller.Configurazione.IncentivoServiceProvider))
self.incentivo_provider.pack()
推荐阅读
- unity3d - 在 Unity 中围绕地球形状的椭球体表面移动
- python - 更新 Conda 后地球引擎 python API 冲突
- mpdf - 有没有办法在使用 MPDF 创建的 pdf 文件中隐藏页脚?
- r - 更正刻度线
- apache-kafka - 添加 SASL 安全性的 Kafka 问题
- performance - 如何在不禁用 locust Web UI 的情况下从命令行运行 locust
- node.js - google oauth 屏幕不显示
- node.js - 无论我是否运行“mongod”,MongoDB 仍然有效
- python - 使用 AJAX 时的 Django 反向匹配
- vcpkg - vcpkg安装后点云库缺少头文件