当我调用方法set_length()
时,我收到错误:
TypeError: can't multiply sequence by non-int of type 'IntVar'
如何修复此问题并简单地执行数学运算?
class Section:
def __init__(self, id, bpm, bars, reps, num_tracks):
self.id = id
self.bpm = IntVar()
self.bpm.set(bpm)
self.bars = IntVar()
self.bars.set(bars)
self.reps = IntVar()
self.reps.set(reps)
self.num_tracks = num_tracks
self.tracks = {}
self.length = IntVar()
self.length.set(bars * 4 / bpm * 60)
def bpm_change(self, value):
self.bpm = value
print(str(self.bpm))
self.set_length()
def bars_change(self, value):
self.bars = value
print(str(self.bars))
self.set_length()
def set_length(self):
self.length = (self.bars * 4 / self.bpm * 60)
答案 0 :(得分:0)
使用self.bpm.get()
和self.bars.get()
获取int
值。
BTW:使用self.bpm.set(value)
,self.bars.set(value)
和self.length.set(value)
代替self.bpm = value
,self.bars = value
和self.length = value