= How to create a gauge (Phoenix) = '''Keywords :''' Gauge. <<TableOfContents>> -------- = Introduction : = {{{wx.Gauge}}} is a widget that is used, when we process lengthy tasks. '''{{{wx.Gauge styles :}}}''' * wx.GA_HORIZONTAL * wx.GA_VERTICAL ||||<style="text-align:center;">'''{{{wx.Gauge methods}}}''' || ||<#d0d0d0>{{{SetRange(integer range)}}} ||<#d0d0d0>set the maximum value of the gauge || ||{{{integer GetRange()}}} ||get the maximum value of the gauge || ||<#d0d0d0>{{{SetValue(integer position)}}} ||<#d0d0d0>set the position of the gauge || ||{{{integer GetValue()}}} ||get the position of the gauge || ||<#d0d0d0>{{{bool IsVertical()}}} ||<#d0d0d0>check if the gauge is vertical || (info by '''JanBodnar / Zetcode'''). -------- = Demonstrating : = __'''''Tested''' py3.x, wx4.x and Win10. ''__ Are you ready to use some samples ? ;) Test, modify, correct, complete, improve and share your discoveries ! (!) -------- == Sample one == {{attachment:img_sample_one.png}} {{{#!python # sample_one.py """ Author : Jan Bodnar Website : zetcode.com """ import wx import random # class MyFrame # class MyApp #--------------------------------------------------------------------------- class MyFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title) self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico', wx.BITMAP_TYPE_ICO)) #------------ self.count = 0 self.timer = wx.Timer(self, 1) #------------ panel = wx.Panel(self, -1) self.gauge = wx.Gauge(panel, -1, 50, size=(250, 25)) self.btn1 = wx.Button(panel, wx.ID_OK, "&Ok") self.btn2 = wx.Button(panel, wx.ID_STOP) self.text = wx.StaticText(panel, -1, 'Task to be done.') #------------ vbox = wx.BoxSizer(wx.VERTICAL) hbox1 = wx.BoxSizer(wx.HORIZONTAL) hbox2 = wx.BoxSizer(wx.HORIZONTAL) hbox3 = wx.BoxSizer(wx.HORIZONTAL) hbox1.Add(self.gauge, 1, wx.ALIGN_CENTRE) hbox2.Add(self.btn1, 1, wx.RIGHT, 10) hbox2.Add(self.btn2, 1) hbox3.Add(self.text, 1) vbox.Add((0, 50), 0) vbox.Add(hbox1, 0, wx.ALIGN_CENTRE) vbox.Add((0, 30), 0) vbox.Add(hbox2, 1, wx.ALIGN_CENTRE) vbox.Add(hbox3, 1, wx.ALIGN_CENTRE) panel.SetSizer(vbox) #------------ self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer) self.Bind(wx.EVT_BUTTON, self.OnOk, self.btn1) self.Bind(wx.EVT_BUTTON, self.OnStop, self.btn2) #------------ self.Centre() #----------------------------------------------------------------------- def OnOk(self, event): if self.count >= 50: return self.timer.Start(100) self.text.SetLabel('Task in Progress.') def OnStop(self, event): if self.count == 0 or self.count >= 50 or not self.timer.IsRunning(): return self.timer.Stop() self.text.SetLabel('Task Interrupted.') wx.Bell() def OnTimer(self, event): self.count = self.count +1 self.gauge.SetValue(self.count) if self.count == 50: self.timer.Stop() self.text.SetLabel('Task Completed.') #--------------------------------------------------------------------------- class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, -1, 'wx.Gauge') frame.Show(True) return True #--------------------------------------------------------------------------- app = MyApp(0) app.MainLoop() }}} -------- = Download source = [[attachment:source.zip]] -------- = Additional Information = '''Link :''' - - - - - https://wiki.wxpython.org/TitleIndex https://docs.wxpython.org/ -------- = Thanks to = Jan Bodnar (sample_one.py coding), the wxPython community... -------- = About this page = Date(d/m/y) Person (bot) Comments : 15/12/20 - Ecco (Created page for wxPython Phoenix). -------- = Comments = - blah, blah, blah....