How to Create SpinButton in wxPython

In this wxPython article i want to show you How To Create SpinButton in wxPython. A wx.SpinButton has two small up and down (or left and right) arrow buttons. So it us used next to a text control. and you can increment and decrements the value

 

 

SpinButton class supports the following styles:

  • wx.SP_HORIZONTAL: Specifies a horizontal spin button (note that this style is not supported in wxGTK).
  • wx.SP_VERTICAL: Specifies a vertical spin button.
  • wx.SP_ARROW_KEYS: The user can use arrow keys to change the value.
  • wx.SP_WRAP: The value wraps at the minimum and maximum.

 

 

 

 

How to Create SpinButton in wxPython?

Let’s create our example, This is the complete code for How To Create SpinButton in wxPython.

 

 

 

 

So this class is MyFrame class that inherits from wx.Frame and it is a top level window that contains our panel.

 

 

 

 

After that we have MyPanel class that inherits from wx.Panel and it is the place that we create our widgets and layouts in this class. You can see that we have created the SpinButton in this class.

 

 

 

 

So this is the TextCtrl that i have created for my SpinButton

 

 

 

 

These are the height and width for our SpinButton

 

 

 

 

And now this is the SpinButton creation

 

 

 

These are the range and value of our SpinButton

 

 

 

In here we bind an event with our SpinButton

 

 

 

And this is the event method

 

 

 

 

 

So the last class is MyApp class that inherits from wx.App. the OnInit() method is where you will most often create frame subclass objects. and start our main loop.That’s it. Once the application’s main event loop processing takes over, control passes to wxPython. Unlike procedural programs, a wxPython GUI program primarily responds to the events taking place around it, mostly determined by a human user clicking with a mouse and typing at the keyboard. When all the human user clicking with a mouse and typing at the keyboard. When all the  return and the program will exit.

 

 

 

 

So run the code and this will be the result

How to Create SpinButton in wxPython
How to Create SpinButton in wxPython

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Share via
Copy link
Powered by Social Snap
×