Hi all i am learning python and wxpython ,now i am stuck while doing spin-ctrl button event,
problem: I have a spin ctrl and few text_ctrl ,spin_ctrl max value is 7 and and it should not set it using max,min or setvalue(). when user goes to 8 or more i want to pop up a message saying that 7 is maximum. or if user enters 8 . i tried to bind it and bring up a message but it comes for each click.:( thanks for your help and spending yo time for my issue in advance. sorry if any mistakes found.
you need to set your max to 8 so that you can get a big enough number and listen to EVT_TEXT
import wx
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Spin Button Tutorial")
panel = wx.Panel(self, wx.ID_ANY)
self.text = wx.SpinCtrl(panel, value="1")
self.text.SetRange(1, 8)
self.text.SetValue(1)
self.text.Bind(wx.EVT_SPINCTRL, self.OnSpin)
self.text.Bind(wx.EVT_TEXT, self.OnSpin)
def OnSpin(self, event):
if self.text.GetValue() > 7:
self.text.SetValue(7)
wx.MessageDialog(self,"Test Message","Too Big!").ShowModal()
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()