Wxpython的规格并不令人耳目一新

时间:2013-06-22 17:13:32

标签: python wxpython

我想用上传量表制作一个上传程序。我有函数,它是回调函数:

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

2 个答案:

答案 0 :(得分:1)

Gauge's range is int type.低于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()

答案 1 :(得分:0)

在文件上传时,您似乎需要一个工作线程来更新GUI。尝试使用线程模块:

import threading

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

threading.Thread(target=myupdater).start()
#upload stuff here