2017-10-07 61 views
0

我试图从各个线圈养活我的进度条国际价值,但我不断收到它说,我不输入int类型的错误:蟒蛇:进度条不接受INT

TypeError: 'int' object does not support item assignment 

我“米做的是:

  1. 获取阵列
  2. 划分长度与阵列长度的进度条的总长度(以获得阵列中值/每个项目百分比)
  3. 每个环路中的值从第二步就丢(INT)获得并添加到总价值VAR
  4. 总价值VAR铸造(INT)并将其分配给我的进度条

位和代码段目前看像这样:

(in main loop) 
.... 
self.progress = Progressbar(self, orient=HORIZONTAL,length=100, mode='determinate') 
global that 
that = self 
def progress_bar(self, progress): 
    progress["value"]=int(progress) 
.... 
(in another worker thread) 
.... 
item_count = 0 
item_percent = 100/len(my_arr) 
for x in my_arr: 
    item_count += 1 
    pb_percent = item_count * item_percent 
    pb_formatted = int(pb_formatted) 
    Application.progress_bar(that, int(pb_formatted)) 

一切似乎对我来说,但我不断收到此错误。当我打印pb_formatted var时,我可以看到它是我需要的进度条,而且我还运行了一些if-else代码块来检查我试图输入的内容是否确实是int

可能是什么问题?

+0

哪一行发生错误? – amrit

回答

1

这是你的问题:

def progress_bar(self, progress): 
    progress["value"]=int(progress) 

progress这里是你传入的说法,说42 42["value"] = int(42)并不意味着什么。你如何将42分配给42的值?换句话说,您不能分配到progress["value"],因为progress不是容器。

您可能想要self.progress=符号的左侧。 self.progress是您的Progressbar实例。

+0

感谢您阅读本文后,我意识到我没有在函数中调用'self.progress'对象,我设置了进度条,我现在就开始工作了。 – lowxkey