wxpython text inside a gauge progress bar

余生颓废 提交于 2020-06-17 14:28:11

问题


I am building an GUI using WxPython, and was wondering if there is a way to put a text inside a gauge progress bar. This is in order to show users the battery status both with image and text.


回答1:


Use the agw.PyGauge

import wx
import wx.lib.agw.pygauge as PG

class MyFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1, "PyGauge Demo", size=(200,100))
        panel = wx.Panel(self)
        gauge1 = PG.PyGauge(panel, -1, size=(100, 25), style=wx.GA_HORIZONTAL)
        gauge1.SetValue(80)
        gauge1.SetDrawValue(draw=True, drawPercent=True, font=None, colour=wx.BLACK, formatString=None)
        gauge1.SetBackgroundColour(wx.WHITE)
        gauge1.SetBorderColor(wx.BLACK)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(gauge1, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 20)
        panel.SetSizer(sizer)
        sizer.Layout()

app = wx.App()
frame = MyFrame(None)
frame.Show()

app.MainLoop()



来源:https://stackoverflow.com/questions/48003668/wxpython-text-inside-a-gauge-progress-bar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!