wxPython中的静态/非动画进度条

wxPython中的静态/非动画进度条,wxpython,progress-bar,Wxpython,Progress Bar,我有一个用wxPython编写的简单GUI,我想显示一个静态的“进度条”,以表示我所连接的设备的电池电量。我尝试过使用wx.Gauge,但不幸的是,它有一个动画光晕(至少在Win10中),正如您在以下两个屏幕截图中看到的: 正如你所看到的,没有什么进展: self.staticBar=wx.Gauge(self,范围=10,尺寸=(200,23),样式=wx.GA_水平) self.staticBar.SetValue(5) 我猜这个动画是Win10UI的一个功能,但是有没有办法在wx中关闭

我有一个用wxPython编写的简单GUI,我想显示一个静态的“进度条”,以表示我所连接的设备的电池电量。我尝试过使用
wx.Gauge
,但不幸的是,它有一个动画光晕(至少在Win10中),正如您在以下两个屏幕截图中看到的:

正如你所看到的,没有什么进展:

self.staticBar=wx.Gauge(self,范围=10,尺寸=(200,23),样式=wx.GA_水平)
self.staticBar.SetValue(5)
我猜这个动画是Win10UI的一个功能,但是有没有办法在wx中关闭它?或者我应该使用另一个类?我试着寻找多色彩带/横幅等(可能我不知道正确的术语是什么,这妨碍了我的搜索),我能找到的最接近的东西是一个
StaticBox
,我用
StaticText
将其拼凑在一起得到:

(最低工作示例):

导入wx
类主面板(wx.Panel):
定义初始化(自身,父级):
wx.Panel.\uuuuu init\uuuuuuuux(self,parent=parent)
子面板=wx.面板(自)
self.staticBar=wx.StaticBox(self,wx.ID_ANY,label=”“,size=(200,35))
self.staticBarFill=wx.StaticText(self.staticBar,wx.ID_ANY,label=”“,size=(100,19))
self.staticBarFill.setbackgroundColor(“绿色”)
子系统=wx.BoxSizer(wx.VERTICAL)
添加(self.staticBarFill,0,wx.TOP,11)
子面板设置器(子面板)
sizer=wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.staticBar,0,wx.ALL,5)
sizer.Add(子面板,0,wx.LEFT,0)
自整定器(施胶器)
类OuterFrame(wx.Frame):
定义初始化(自):
wx.Frame.\uuuuu init\uuuuuuuuuuuuuuuuuuuuuuuuux.ID\u ANY,大小=(300200))
self.Center()#屏幕上的中心gui
主面板(自身)
如果名称=“\uuuuu main\uuuuuuuu”:
app=wx.app()
frame=OuterFrame().Show()
app.MainLoop()
事实上,我对此没有意见,只是我似乎无法更改
静态文本的大小。我可以在
StaticText
上调用
SetSize
,它不会抛出错误,但也不会做任何事情(它在文档中也没有作为方法列出,所以可能没有实现?)


那么基本上,wxPython中是否有某种非动画的“进度条”?如果没有,我怎样才能拼凑出一个类似进度条/电池电量指示器的东西,并且可以进行更新/调整大小?

这里有几个选项:
请注意,
静态框
不会显示在我的显示外观
主题
,请记住这一点。我用了背景色来处理它

import wx
import wx.lib.agw.pygauge as PG
from random import randrange

class MainFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent=None)
        self.level = 100
        panel = wx.Panel(self)
        panel.SetBackgroundColour("gray")
        self.battery_level = wx.Slider(panel, -1, value=self.level, minValue=0, maxValue=100, size=(200, 50), style=wx.SL_LABELS)
        self.battery_level.Enable(False)

        self.staticBar = wx.StaticBox(panel, wx.ID_ANY, label="Battery life", size=(200,35))
        self.staticBarFill = wx.StaticText(self.staticBar, wx.ID_ANY, label="", size=(195,30))
        self.staticBar.SetBackgroundColour("lightgreen")
        self.staticBarFill.SetForegroundColour("darkgreen")
        self.staticBarFill.SetLabel("|"*self.level)

        self.gBar = wx.Gauge(panel, wx.ID_ANY, size=(200,35))
        self.gBar.SetValue(self.level)

        self.gText = wx.TextCtrl(panel, wx.ID_ANY, value="|"*self.level, size=(self.level*2,30))
        self.gText.SetBackgroundColour("lightgreen")
        self.gText.SetForegroundColour("darkgreen")

        self.pg = PG.PyGauge(panel, -1, size=(200, 35), style=wx.GA_HORIZONTAL)
        self.pg.SetValue(self.level)
        self.pg.SetDrawValue(draw=True, drawPercent=True, font=None, colour=wx.BLACK, formatString="Battery life")
        self.pg.SetBackgroundColour(wx.WHITE)
        self.pg.SetBorderColor(wx.BLACK)
        print(dir(self.pg))

        self.button = wx.Button(panel, -1, "Adjust")
        self.button.Bind(wx.EVT_BUTTON, self.OnAdjust)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.battery_level, 0, wx.ALL,10)
        sizer.Add(self.staticBar, 0, wx.ALL,10)
        sizer.Add(self.gBar, 0, wx.ALL,10)
        sizer.Add(self.gText, 0, wx.ALL,10)
        sizer.Add(self.pg, 0, wx.ALL,10)
        sizer.Add(self.button, 0, wx.ALL,10)
        panel.SetSizer(sizer)
        self.Show()

    def OnAdjust(self, event):
        self.level = randrange(1,100)
        self.battery_level.SetValue(self.level)
        self.staticBarFill.SetSize(self.level*2, 35)
        self.gBar.SetValue(self.level)
        self.gText.SetSize(self.level*2, 35)
        self.pg.SetValue(self.level)
        if self.level > 25:
            self.pg.SetBarColour("green")
        else:
            self.pg.SetBarColour("red")
        self.pg.SetDrawValue(draw=True, drawPercent=True, font=None, colour=wx.BLACK, formatString="Battery life "+str(self.level)+"%")
        self.Refresh()

if __name__ == "__main__":
    app = wx.App()
    frame = MainFrame(None)
    app.MainLoop()

这里有几个选项:
请注意,
静态框
不会显示在我的显示外观
主题
,请记住这一点。我用了背景色来处理它

import wx
import wx.lib.agw.pygauge as PG
from random import randrange

class MainFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent=None)
        self.level = 100
        panel = wx.Panel(self)
        panel.SetBackgroundColour("gray")
        self.battery_level = wx.Slider(panel, -1, value=self.level, minValue=0, maxValue=100, size=(200, 50), style=wx.SL_LABELS)
        self.battery_level.Enable(False)

        self.staticBar = wx.StaticBox(panel, wx.ID_ANY, label="Battery life", size=(200,35))
        self.staticBarFill = wx.StaticText(self.staticBar, wx.ID_ANY, label="", size=(195,30))
        self.staticBar.SetBackgroundColour("lightgreen")
        self.staticBarFill.SetForegroundColour("darkgreen")
        self.staticBarFill.SetLabel("|"*self.level)

        self.gBar = wx.Gauge(panel, wx.ID_ANY, size=(200,35))
        self.gBar.SetValue(self.level)

        self.gText = wx.TextCtrl(panel, wx.ID_ANY, value="|"*self.level, size=(self.level*2,30))
        self.gText.SetBackgroundColour("lightgreen")
        self.gText.SetForegroundColour("darkgreen")

        self.pg = PG.PyGauge(panel, -1, size=(200, 35), style=wx.GA_HORIZONTAL)
        self.pg.SetValue(self.level)
        self.pg.SetDrawValue(draw=True, drawPercent=True, font=None, colour=wx.BLACK, formatString="Battery life")
        self.pg.SetBackgroundColour(wx.WHITE)
        self.pg.SetBorderColor(wx.BLACK)
        print(dir(self.pg))

        self.button = wx.Button(panel, -1, "Adjust")
        self.button.Bind(wx.EVT_BUTTON, self.OnAdjust)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.battery_level, 0, wx.ALL,10)
        sizer.Add(self.staticBar, 0, wx.ALL,10)
        sizer.Add(self.gBar, 0, wx.ALL,10)
        sizer.Add(self.gText, 0, wx.ALL,10)
        sizer.Add(self.pg, 0, wx.ALL,10)
        sizer.Add(self.button, 0, wx.ALL,10)
        panel.SetSizer(sizer)
        self.Show()

    def OnAdjust(self, event):
        self.level = randrange(1,100)
        self.battery_level.SetValue(self.level)
        self.staticBarFill.SetSize(self.level*2, 35)
        self.gBar.SetValue(self.level)
        self.gText.SetSize(self.level*2, 35)
        self.pg.SetValue(self.level)
        if self.level > 25:
            self.pg.SetBarColour("green")
        else:
            self.pg.SetBarColour("red")
        self.pg.SetDrawValue(draw=True, drawPercent=True, font=None, colour=wx.BLACK, formatString="Battery life "+str(self.level)+"%")
        self.Refresh()

if __name__ == "__main__":
    app = wx.App()
    frame = MainFrame(None)
    app.MainLoop()

除了萨克森州的罗尔夫给出的非常好的答案外,您还可以检查:


除了萨克森州的罗尔夫给出的非常好的答案外,您还可以检查:


这正是我想要的。似乎这个答案(也是由Rolf提供的)也是相关的:请接受我的道歉,因为我在事后加入了我在2017年提出的解决方案,正如上文asdf所指出的那样这正是我想要的。似乎这个答案(也是由Rolf提供的)也是相关的:请接受我的道歉,因为我在事后加入了我在2017年提出的解决方案,正如上文asdf所指出的那样作为回报,这些选项在windows用户界面上不起作用。然而,它确实给了我一些不同的想法,让我尝试一下display@asdf有趣的是,我忘记了我以前的答案。我知道还有另一个选择,就是想不起来。我添加它只是为了形式。我确实觉得很有趣。看来你是wxPython的MVPhere@asdf似乎你忘记了
Mr
Robin Dunn和@VZ(Vadz)可悲的是,这些选项在windows用户界面上不起作用。然而,它确实给了我一些不同的想法,让我尝试一下display@asdf有趣的是,我忘记了我以前的答案。我知道还有另一个选择,就是想不起来。我添加它只是为了形式。我确实觉得很有趣。看来你是wxPython的MVPhere@asdf好像你忘了
Mr
Robin Dunn和@VZ(Vadz)