Welcome folks today in this blog post we will be looking at wxpython range slider class widget with values
. All the full source code of the application is given below.
Get Started
In order to get started you need to install the below library using the pip
command as shown below
pip install wxpython
After installing this library you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import wx class Mywin(wx.Frame): def __init__(self, parent, title): super(Mywin, self).__init__(parent, title = title,size = (250,150)) self.InitUI() def InitUI(self): pnl = wx.Panel(self) vbox = wx.BoxSizer(wx.VERTICAL) self.sld = wx.Slider(pnl, value = 10, minValue = 1, maxValue = 100, style = wx.SL_HORIZONTAL|wx.SL_LABELS) vbox.Add(self.sld,1,flag = wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, border = 20) self.sld.Bind(wx.EVT_SLIDER, self.OnSliderScroll) self.txt = wx.StaticText(pnl, label = 'Hello',style = wx.ALIGN_CENTER) vbox.Add(self.txt,1,wx.ALIGN_CENTRE_HORIZONTAL) pnl.SetSizer(vbox) self.Centre() self.Show(True) def OnSliderScroll(self, e): obj = e.GetEventObject() val = obj.GetValue() font = self.GetFont() font.SetPointSize(self.sld.GetValue()) self.txt.SetFont(font) ex = wx.App() Mywin(None,'Slider demo') ex.MainLoop() |
If you execute the above python script
by typing the below command
python app.py