2

我无法启动进度条。我在互联网上搜索了答案,并尝试了数小时的多种方法,但得到了以下错误的回报:

TypeError: unbound method start() must be called with Progressbar instance as first argument (got nothing instead)

TypeError: unbound method start() must be called with Progressbar instance as first argument (got NoneType instance instead)

AttributeError: 'NoneType' object has no attribute 'stop'

这是(基本上)我的代码:

from Tkinter import *
import ttk

def foo():
    #make progressbar start here
    do_stuff()
    #make progressbar end here


root = Tk()
root.title("foo")

mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
prog = ttk.Progressbar(mainframe, mode='indeterminate').grid(column=1, row=100, sticky=W)

ttk.Button(mainframe, text="Check", command=foo).grid(column=1, row=100, sticky=E)

for child in mainframe.winfo_children():
    child.grid_configure(padx=5, pady=5)
root.bind('<Return>', check)

root.mainloop()
4

1 回答 1

4

您的 prog 变量不包含进度条,因为您调用了返回 None 的 grid 方法。这确实解释了

AttributeError: 'NoneType' object has no attribute 'stop'

将您的代码更改为

prog = ttk.Progressbar(mainframe, mode='indeterminate')
prog.grid(column=1, row=100, sticky=W)

之后,您可以通过 foo 启动 Progressbar

prog.start()
于 2011-06-02T16:12:17.583 回答