0
def creabackuno():
  startbar()
  messagebox.showinfo( "Wait..","I am creating the backup, please wait...")
  try:
      copytree(path,r"backup\dirbackup1\.minecraft")
      messagebox.showinfo( "OK!","Backup (1) created!")
      stopbar()
  except OSError as exc:
      messagebox.showerror( "Nope!","There is already a backup to restore")
      stopbar()

I have a problem with a progressbar:

The startbar() start the progressbar on the graphic interface, but when start shutil(copytree(path,r"backup\dirbackup1.minecraft")) the interface freezing and the progressbar stop until it finished. thanks

i'm using python 3.3

sorry for my poor english

4

3 回答 3

1

进度条显示什么?如果您试图显示复制的文件的百分比,那么您必须首先获取文件的总长度/字节,然后使用复制的字节数定期更新。这将需要使用“之后”每隔这么多毫秒检查一次复制到文件的大小(我想我只是在这里猜测,但首先搜索,因为必须有人已经做过这样的事情。)这个是我找到的第一个链接https://mail.python.org/pipermail/tkinter-discuss/2010-December/002613.html 它可能比你想要的更多,但应该有所帮助。

于 2013-09-23T19:30:00.023 回答
1

copytree是一个同步函数,所以所有代码执行都会停止,直到它完成。虽然 tkinter 很遗憾没有线程安全,但我建议您将该命令放在另一个线程中:

from thread import start_new_thread as snt
#from _thread import start_new_thread as snt for python 3

def copy(onError,onEnd):
    try: copytree(path,r"backup\dirbackup1\.minecraft")
    except: 
       onError()
       return
    onEnd()

def onEnd():
    messagebox.showinfo( "OK!","Backup (1) created!")
    stopbar()

def onError():
      messagebox.showerror( "Nope!","There is already a backup to restore")
      stopbar()

#then call with

snt(copy,(onError,onEnd))

如果失败则执行 onError,成功则执行 onEnd。

于 2013-09-23T18:07:11.413 回答
0

self.Frame.update_idletasks()在每条语句之后使用self.pgBar.step(x),其中“x”代表进度条值增加的值

于 2013-09-25T04:31:48.990 回答