<p>我正在尝试为暑期工作创建一个GUI BMI计算器。
我想实现一个功能,一旦你的BMI被计算出来,标签的颜色会根据你的BMI而改变。在</p>
<p>我现在的代码是:</p>
<pre><code>self.AnswerlabelVariable = tkinter.StringVar() #Creates a variable used later for changing the label text
Answerlabel = tkinter.Label(self, text=u" ", textvariable=self.AnswerlabelVariable, anchor='w', fg="black",bg="light grey") #Creates a label
Answerlabel.grid(column=1,row=4, sticky='EW') #Defines where the label is and how it will move
...the calculation for the BMI happens...
if float(BMI2)<int(17): #Creates an 'if' statement
self.MessagelabelVariable.set("You are underweight!") #Changes a label to display a new message.
self.AnswerlabelVariable.set(fg='black', bg='blue') #Changes a labels colour (WIP WIP WIP)
</code></pre>
<p>当标签改变了它的文本,颜色没有改变,而是产生一个错误信息</p>
^{pr2}$
<p>有人能帮忙吗?在</p>