2011-06-02 49 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