我想教自己python並遇到一個錯誤,我不確定。錯誤看起來是這樣的:TypeError:不支持的操作數類型爲*:'type'和'float'
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'
我知道錯誤是告訴我,我不能乘這兩種類型,我很困惑什麼「類型」是。任何人都可以幫我清除這個錯誤。下面的完整代碼。
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()
謝謝你的答案我加括號的所有任務現在的錯誤說:。 類型錯誤:不支持的操作類型爲*: 'DoubleVar'和'浮動' 我嘗試將fmML,fgML和fbML分配爲DoubleVar,但彈出同樣的錯誤。 – Edyoucaterself