Control on 'Button' avilability

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SurekhaP
    New Member
    • Nov 2011
    • 4

    Control on 'Button' avilability

    Hi all,

    I am using wxPython for creating GUI. Suppose we have 2 buttons, one for 'CONNECT' and the other for 'DISCONNECT' in some telnet application. There is no point in having the 'DISCONNECT' button active before 'CONNECT' button is pressed and the connection is established.

    So, we may need to make a button active/inactive based on our logic need. Is there anyway we can acheive this?

    please help!
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    In Tkinter, you could disable the 'DISCONNECT' button when you are not connected like this:
    Code:
    self.btnList[0].configure(state=DISABLED)
    In the example, self.btnList[0] is a 'START' button. After the 'START' button is picked, the 'START' button command callback executes the above code and the button becomes greyed out.

    Comment

    • dwblas
      Recognized Expert Contributor
      • May 2008
      • 626

      #3
      When the connectection is established, set some variable to True and change the disconnect button's background to the 'active color', and then test for True/False in the disconnect function (which would set it to False). This is very easy using a class and instance variables, so it you are not coding this within a class it would be a good idea to learn something first and to go back and redo the program before it gets out of hand.

      Comment

      Working...