我正在运行一个使用LaTeX构建一组PDF的缓慢过程,这个过程由我的脚本组合而成。
PDF是在一个for循环中构建的。我想要显示一个状态窗口,它将为循环所通过的每个学生添加一行,这样您就可以看到进度。我一直在用print来做这件事,但我想要的是与我移动到的Tkinter界面很好地集成在一起的东西。
我有这个:
ReStatuswin = Toplevel(takefocus=True)
ReStatuswin.geometry('800x300')
ReStatuswin.title("Creating Reassessments...")
Rebox2 = MultiListbox(ReStatuswin, (("Student", 15), ("Standard", 25), ("Problems", 25) ))
Rebox2.pack(side = TOP)
OKR = Button(ReStatuswin, text='OK', command=lambda:ReStatuswin.destroy())
OKR.pack(side = BOTTOM)然后循环:
for row in todaylist:然后,在循环内部,在PDF文件生成之后,
Rebox2.insert(END, listy)它很好地插入了行,但是它们都是在整个循环完成后才出现的(以及ReBox2窗口本身)。
知道是什么导致了展览的延迟吗?
谢谢!
发布于 2013-07-26 16:44:45
是的,据我所知,有两个问题。首先,不使用每个新条目更新显示。其次,不是用按钮触发for循环,而是在启动时运行它(这意味着在循环退出后才会创建显示)。但是,不幸的是,我不能真正使用您给出的代码,因为它是一个大得多的代码片段。但是,我编写了一个应该演示如何做您想做的事情的小脚本:
from Tkinter import Button, END, Listbox, Tk
from time import sleep
root = Tk()
# My version of Tkinter doesn't have a MultiListbox
# So, I use its closest alternative, a regular Listbox
listbox = Listbox(root)
listbox.pack()
def start():
"""This is where your loop would go"""
for i in xrange(100):
# The sleeping here represents a time consuming process
# such as making a PDF
sleep(2)
listbox.insert(END, i)
# You must update the listbox after each entry
listbox.update()
# You must create a button to call a function that will start the loop
# Otherwise, the display won't appear until after the loop exits
Button(root, text="Start", command=start).pack()
root.mainloop()https://stackoverflow.com/questions/17886015
复制相似问题