Python 3 WxPython Horizontal Range Slider Class Widget With Values Example in GUI Desktop App Full Project For Beginners

You are currently viewing Python 3 WxPython Horizontal Range Slider Class Widget With Values Example in GUI Desktop App Full Project For Beginners

 

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

 

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

 

 

Leave a Reply