1

我想制作一个带有上传量规的上传程序。我有一个回调函数:

def myupdater(self, current, total):

    m = (Decimal(current)/Decimal(total))
    print "uploaded {0}/{1} so far".format(current, total)
    self.gauge_1.SetValue(m)
    print(m)
    print (self.gauge_1.GetValue)
    wx.Yield()
    print"----------------------"

它显示(最后仪表只更改为 100%):

http://pastebin.com/eM40e6mv

完整代码: http: //pastebin.com/uaThd5sD

4

2 回答 2

1

Gauge的范围是 int 类型。传递值小于 1 被视为 0。更改gauge_1 ..行如下:

self.gauge_1 = wx.Gauge(self.notebook_1_pane_1, -1, 100)

更改myupdater如下:

def myupdater(self, current, total):
    m = 100 * current / total
    self.gauge_1.SetValue(m)
    wx.Yield()
于 2013-06-22T17:55:00.927 回答
0

看起来您需要一个工作线程来在文件上传时更新您的 GUI。尝试线程模块:

import threading

def myupdater(self):
    while self.still_uploading:
        #do stuff

threading.Thread(target=myupdater).start()
#upload stuff here
于 2013-06-22T17:24:09.637 回答