仪表进度条内的 wxpython 文本 [英] wxpython text inside a gauge progress bar
本文介绍了仪表进度条内的 wxpython 文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 WxPython 构建 GUI,并且想知道是否有办法将文本放入仪表进度条中.这是为了通过图像和文本向用户显示电池状态.
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.
推荐答案
使用 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 | wx.ALL, 20)
panel.SetSizer(sizer)
sizer.Layout()
app = wx.App()
frame = MyFrame(None)
frame.Show()
app.MainLoop()
对于比百分比更具描述性的文本,请尝试使用 formatString
参数,并可能根据百分比值选择不同的背景颜色.
For more descriptive text than a percentage, experiment with the formatString
parameter and perhaps choose different background colours, dependent upon the percentage value.
这篇关于仪表进度条内的 wxpython 文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文