2011-06-02 51 views
1

我在获取进度条启动时遇到问题。我已经冲刷答案互联网,并尝试多种方式好几个小时,但都被奖励的错误,如:Python ttk.Progressbar

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'

我是相当新的Python的,因此,如果任何人都可以在正确的方向指向我,将非常感激。

这里是(本质)我的代码:

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() 

回答

2

你PROG变量不包含的进度,因为你叫这确实返回无网格法。那请问你的代码解释

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

变化

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

后,你可以在FOO通过

prog.start() 
+0

开始任职的进度!谢谢。 – Nino 2011-06-02 21:44:57