如何启动ttk.Progressbar? [英] How to start ttk.Progressbar?

查看:110
本文介绍了如何启动ttk.Progressbar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法启动进度栏。我搜寻了互联网上的答案,并尝试了数小时的多种方法,但由于以下错误而受到奖励:

I am having trouble with getting the progressbar to start. I have scoured the internet for answers, and have tried multiple ways for hours, but have been rewarded with errors such as:

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'

(基本上)是我的代码:

Here is (essentially) my code:

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


推荐答案

您的prog变量不包含进度条,因为您调用了返回无值的网格方法。确实可以解释

Your prog variable does not contain the progressbar because you call the grid method which does return None. That does explain the

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

将代码更改为

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

之后,您可以通过以下方式在foo中启动进度栏:

after that you can start the Progressbar in foo via

prog.start()

这篇关于如何启动ttk.Progressbar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆