Just wondering if anyone has experience with wxPython. I've been looking for info about the spinButton I want to increment it at 5's or 10's just wondering if anyone has some quit hints or info.


Thanks

Here is a quick way (written with the Boa Constructor) to do this ...

#-----------------------------------------------------------------------------
# Name:        Test2.py
# Purpose:     Spinbutton with label that allows values to be
#              incremented or decremented by other than 1
#
# Author:      <your name>
#
# Created:     2007/12/31
# RCS-ID:      $Id: Test2.py $
# Copyright:   (c) 2006
# Licence:     <your licence>
#-----------------------------------------------------------------------------
#Boa:Frame:Frame1

import wx

def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1PANEL1, wxID_FRAME1SPINBUTTON1, 
 wxID_FRAME1STATICTEXT1, wxID_FRAME1STATICTEXT2, 
] = [wx.NewId() for _init_ctrls in range(6)]

class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(357, 150), size=wx.Size(325, 214),
              style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
        self.SetClientSize(wx.Size(317, 174))
        self.SetBackgroundColour(wx.Colour(255, 255, 128))
        self.SetWindowVariant(wx.WINDOW_VARIANT_LARGE)

        self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
              pos=wx.Point(0, 0), size=wx.Size(317, 174),
              style=wx.RAISED_BORDER)

        self.spinButton1 = wx.SpinButton(id=wxID_FRAME1SPINBUTTON1,
              name='spinButton1', parent=self.panel1, pos=wx.Point(168, 24),
              size=wx.Size(23, 21), style=wx.SP_VERTICAL)
        self.spinButton1.Bind(wx.EVT_SPIN_UP, self.OnSpinButton1SpinUp,
              id=wxID_FRAME1SPINBUTTON1)
        self.spinButton1.Bind(wx.EVT_SPIN_DOWN, self.OnSpinButton1SpinDown,
              id=wxID_FRAME1SPINBUTTON1)

        self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1, label='0',
              name='staticText1', parent=self.panel1, pos=wx.Point(80, 24),
              size=wx.Size(83, 21), style=0)

        self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label='Get Value',
              name='button1', parent=self.panel1, pos=wx.Point(80, 64),
              size=wx.Size(104, 31), style=0)
        self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
              id=wxID_FRAME1BUTTON1)

        self.staticText2 = wx.StaticText(id=wxID_FRAME1STATICTEXT2,
              label='                  ', name='staticText2',
              parent=self.panel1, pos=wx.Point(80, 112), size=wx.Size(90, 21),
              style=0)

    def __init__(self, parent):
        self._init_ctrls(parent)
        self.spin_val = 0
        self.spin_increment = 5

    def OnSpinButton1SpinUp(self, event):
        # increment
        self.spin_val += self.spin_increment
        # set the value of the label associated with the spinbutton
        self.staticText1.SetLabel(str(self.spin_val))
        event.Skip()

    def OnSpinButton1SpinDown(self, event):
        # decrement
        self.spin_val -= self.spin_increment
        # set the value of the label associated with the spinbutton
        self.staticText1.SetLabel(str(self.spin_val))        
        event.Skip()

    def OnButton1Button(self, event):
        # get the value of the label associated with the spinbutton
        self.staticText2.SetLabel(self.staticText1.GetLabel())
        event.Skip()


if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = create(None)
    frame.Show()

    app.MainLoop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.