Python 3.x 为什么在Tkinter中尝试更新Progressbar的value属性时会出现类型错误?

Python 3.x 为什么在Tkinter中尝试更新Progressbar的value属性时会出现类型错误?,python-3.x,tkinter,progress-bar,typeerror,Python 3.x,Tkinter,Progress Bar,Typeerror,我正在使用Python 3.8.2 下面的代码有3个主循环。我需要一个简单的UI来显示每个循环的进度 import tkinter as tk from tkinter import filedialog, ttk from tkinter.ttk import Progressbar import json class App(tk.Tk): def __init__(self): tk.Tk.__init__(self) self.filename

我正在使用Python 3.8.2 下面的代码有3个主循环。我需要一个简单的UI来显示每个循环的进度

import tkinter as tk
from tkinter import filedialog, ttk
from tkinter.ttk import Progressbar
import json
class App(tk.Tk):

    def __init__(self):
        tk.Tk.__init__(self)
        self.filename = ''
        tk.Button(self, text = 'Upload File', command = self.get_file).grid(row = 0, column = 0)
        tk.Button(self, text = 'Verify', command = self.verify).grid(row = 1, column = 0)
        # tk.Label(self, text = 'some name').grid(row = 0, column = 1)
        self.mainloop()

    def get_file(self):
        self.filename = tk.filedialog.askopenfilename(title = "Select File", filetypes = [("JSON", "*.json")])
        tk.Label(self, text = self.filename).grid(row = 0, column = 1)
    def verify(self):
        tk.Label(self, text = 'Verifying Trustee Public Keys').grid(row = 2, column = 0)
        ttk.Progressbar(self,
                   length = 100,
                   orient = "horizontal",
                   maximum = len(self.data["trustee_public_keys"]),
                   value = 0).grid(row = 3, column = 0)
        i = 1
        for trustee_key_list in self.data['trustee_public_keys']:
            print('Trustee :', i)
            //some code
            i = i+1
            ttk.Progressbar['value'] =  i
每次运行时,我都会收到错误:

 File "C:/Users/Student User/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/scratch_17.py", line 81, in verify
ttk.Progressbar['value'] =  i
TypeError: 'type' object does not support item assignment

我做错了什么?如何获得预期的结果?

您的代码尝试为progressbar类型分配值,而您应该将值分配给progressbar的实例

def verify(self):
        tk.Label(self, text = 'Verifying Trustee Public Keys').grid(row = 2, column = 0)
        progress = ttk.Progressbar(self,
                   length = 100,
                   orient = "horizontal",
                   maximum = len(self.data["trustee_public_keys"]),
                   value = 0)
        progress.grid(row = 3, column = 0)
        i = 1
        for trustee_key_list in self.data['trustee_public_keys']:
            print('Trustee :', i)
            //some code
            i = i+1
            progress['value'] =  i