【问题标题】:How to start ttk.Progressbar?如何启动 ttk.Progressbar?
【发布时间】:2011-06-02 09:50:04
【问题描述】:

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

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

【问题讨论】:

    标签: python debugging progress-bar ttk


    【解决方案1】:

    您的 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 启动进度条

    prog.start()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-29
      • 2012-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-31
      • 2013-09-13
      相关资源
      最近更新 更多