Edy*_*elf -2 python tkinter python-3.x
我正在尝试自学python并遇到了一个我不确定的错误.错误看起来像这样:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.2/tkinter/__init__.py", line 1426, in __call__
return self.func(*args)
File "/home/pi/python/SolutionMixerGUI.py", line 39, in calculate
fgTotal = self.vol * fgML
TypeError: unsupported operand type(s) for *: 'type' and 'float'
Run Code Online (Sandbox Code Playgroud)
我知道这个错误告诉我,我不能将这两种类型相乘,我很困惑'类型'是什么.任何人都可以帮我清除这个错误.完整代码如下.
from tkinter import *
class App:
def __init__(self,master):
frame = Frame(master)
frame.pack()
Label(frame, text='Solution in liters:').grid(row=0, column=0)
self.vol = DoubleVar
Entry(frame, textvariable=self.vol).grid(row=0, column=1)
Label(frame, text='Growth Stage (1-5):').grid(row=1, column=0)
self.stage = IntVar
Entry(frame, textvariable=self.stage).grid(row=1, column=1)
self.fgTotal = DoubleVar
self.fmTotal = DoubleVar
self.fbTotal = DoubleVar
Label(frame, textvariable=self.fgTotal).grid(row=2, column=0)
Label(frame, textvariable=self.fmTotal).grid(row=2, column=2)
Label(frame, textvariable=self.fbTotal).grid(row=2, column=3)
button = Button(frame, text='Calculate', command=self.calculate)
button.grid(row=3, column=1, sticky=(W, E))
def calculate(self):
if self.stage == 1:
#Seedlings
fgML,fmML,fbML = 0.33,0.33,0.33
elif self.stage == 2:
#Mild Veg
fgML,fmML,fbML = 1.32,1.32,1.32
elif self.stage == 3:
#Aggresive Veg
fgML,fmML,fbML = 3.96,2.64,1.32
elif self.stage == 4:
#Tranistion to Bloom
fgML,fmML,fbML = 2.64,2.64,2.64
else:
#Blooming and Ripening
fgML,fmML,fbML = 1.32,2.64,3.96
fgTotal = self.vol * fgML
fmTotal = self.vol * fmML
fbTotal = self.vol * fbML
root = Tk()
root.wm_title('Solution Mixer')
app = App(root)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1409 次 |
| 最近记录: |