Python ttk.Progressbar [英] Python ttk.Progressbar
问题描述
TypeError:unbound必须使用Progressbar实例调用方法start()作为第一个参数(没有任何代替)
TypeError:未绑定的方法start()必须使用Progressbar实例作为第一个参数得到了NoneType实例)
AttributeError:'NoneType'对象没有属性'stop'
我对Python很新,所以如果有人能指出我正确的方向,将非常感激。
这是(本质上)我的代码:
从Tkinter导入*
import ttk
def foo():
#make progressbar从这里开始
do_stuff()
#make progressbar end here
root = Tk()
root.title( foo)
mainfr ame = ttk.Frame(root,padding =3 3 12 12)
mainframe.grid(column = 0,row = 0,sticky =(N,W,E,S))
主机.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 mainframe.winfo_children()中的child:
child.grid_configure(padx = 5,pady = 5)
root.bind('<返回>',检查)
root.mainloop()
您的prog变量不包含进度条,因为您调用了返回None的grid方法。这就解释了
AttributeError:'NoneType'对象没有属性'stop'
将您的代码更改为
prog = ttk .Progressbar(mainframe,mode ='indeterminate')
prog.grid(column = 1,row = 100,sticky = W)
之后,您可以通过
prog.start()$启动进度条b $ b
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'
I am fairly new to Python, so if anyone could point me in the right direction that would be very much appreciated.
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()
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'
change your code to
prog = ttk.Progressbar(mainframe, mode='indeterminate')
prog.grid(column=1, row=100, sticky=W)
after that you can start the Progressbar in foo via
prog.start()
这篇关于Python ttk.Progressbar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!