Changing button preferences after beeing pressed

Discussion in 'Python' started by thomas.lidebrandt@gmail.com, Aug 16, 2007.

  1. Guest

    Hello

    I'm using wxPython to consruct a GUI and want to change a button label
    and event handler to change after the button have been pressed. The
    only thing I can think of is a global variable that contrls the state
    of the program and constructs the button in accordance to the defined
    state. Is there a better solution to this problem?

    /Thomas
     
    , Aug 16, 2007
    #1
    1. Advertising

  2. wrote:
    > I'm using wxPython to consruct a GUI and want to change a button
    > label


    => wx.Button.SetLabel (also have a look at the button examples)

    > and event handler to change after the button have been
    > pressed.


    I'm not sure if those bindings can easily be changed at runtime.
    Another solution is creating two buttons and only show one at a
    time.

    > The only thing I can think of is a global variable that
    > contrls the state of the program and constructs the button in
    > accordance to the defined state.


    Better keep the state as frame attribute and use a frame method to
    change it.

    Regards,


    Björn

    --
    BOFH excuse #61:

    not approved by the FCC
     
    Bjoern Schliessmann, Aug 16, 2007
    #2
    1. Advertising

  3. Steve Holden Guest

    wrote:
    > Hello
    >
    > I'm using wxPython to consruct a GUI and want to change a button label
    > and event handler to change after the button have been pressed. The
    > only thing I can think of is a global variable that contrls the state
    > of the program and constructs the button in accordance to the defined
    > state. Is there a better solution to this problem?
    >

    It would be difficult to think of a worse one! ;-)

    Since the button is probably in some sort of window, you should at least
    be saving the state as an instance variable of the window. The event
    handler should start with an "if" statement that calls one or other of
    the routines you have in mind depending on state. Here's a button
    event-handlerI use in a time recording program:

    def OnPauseRestart(self, event):
    """Stops/restarts the clock: allows for non-recordable
    activities."""
    if self.Running:
    self.stopTimer()
    else:
    self.startTimer()

    def startTimer(self):
    """Starts the timer and returns the time to black."""
    if not self.currentTask:
    msg("Please select a task before starting the timer",
    caption="No current task")
    return
    self.timer.Start(1000)
    self.Time().SetForegroundColour(wx.BLACK)
    self.Time().Refresh()
    self.Pause().SetLabel("&Pause")
    self.Running = 1

    def stopTimer(self):
    """Stops the timer and sets the time red - you are not
    chargeable!"""
    self.timer.Stop()
    self.Time().SetForegroundColour(wx.RED)
    self.Time().Refresh()
    self.Pause().SetLabel("&Resume")
    self.Running = 0

    Hope this helps.

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://del.icio.us/steve.holden
    --------------- Asciimercial ------------------
    Get on the web: Blog, lens and tag the Internet
    Many services currently offer free registration
    ----------- Thank You for Reading -------------
     
    Steve Holden, Aug 16, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Earl Teigrob
    Replies:
    0
    Views:
    581
    Earl Teigrob
    Dec 15, 2003
  2. Rune
    Replies:
    6
    Views:
    1,312
    Richie Hindle
    Jan 29, 2004
  3. Novice

    Leave button depressed after being pressed

    Novice, Jun 21, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    433
    Ken Cox [Microsoft MVP]
    Jun 23, 2004
  4. Replies:
    4
    Views:
    320
    Ray Costanzo [MVP]
    Oct 4, 2005
  5. Chuck
    Replies:
    0
    Views:
    294
    Chuck
    Nov 10, 2003
Loading...

Share This Page