TypeError:不能将序列乘以'IntVar'类型的非int

时间:2015-11-27 06:19:16

标签: python variables math tkinter typeerror

当我调用方法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)

1 个答案:

答案 0 :(得分:0)

使用self.bpm.get()self.bars.get()获取int值。

BTW:使用self.bpm.set(value)self.bars.set(value)self.length.set(value)代替self.bpm = valueself.bars = valueself.length = value