tkinter button state = DISABLED

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rahulnag22@yahoo.com

    #1

    tkinter button state = DISABLED

    I have created a button widget with a button click binding. The button
    initially has a state=disabled. I can see the greyed out version of
    the button in the GUI. But If I click on the button it still invokes
    the callback/binding function.

    Any suggestions as to why the callback is being invoked even though
    the button has a disabled state. It looks like-

    b=Button(frame, text = "Button", state = 'disabled')

    b.bind("<Button Release-1>",
    lambda
    event :
    function()
    )

    Thanks
    Rahul

  • Peter Otten

    #2
    Re: tkinter button state = DISABLED

    rahulnag22@yaho o.com wrote:
    I have created a button widget with a button click binding. The button
    initially has a state=disabled. I can see the greyed out version of
    the button in the GUI. But If I click on the button it still invokes
    the callback/binding function.
    >
    Any suggestions as to why the callback is being invoked even though
    the button has a disabled state. It looks like-
    >
    b=Button(frame, text = "Button", state = 'disabled')
    >
    b.bind("<Button Release-1>",
    lambda
    event :
    function()
    )
    Well, the /mouse/ button /was/ released. Do you know about the alternative?

    b = Button(..., command=functio n) # no bind(), no lambda

    It behaves like you expect.

    Peter

    Comment

    • rahulnag22@yahoo.com

      #3
      Re: tkinter button state = DISABLED

      On May 14, 12:01 pm, Peter Otten <__pete...@web. dewrote:
      rahulna...@yaho o.com wrote:
      I have created a button widget with a button click binding. The button
      initially has a state=disabled. I can see the greyed out version of
      the button in the GUI. But If I click on the button it still invokes
      the callback/binding function.
      >
      Any suggestions as to why the callback is being invoked even though
      the button has a disabled state. It looks like-
      >
      b=Button(frame, text = "Button", state = 'disabled')
      >
      b.bind("<Button Release-1>",
      lambda
      event :
      function()
      )
      >
      Well, the /mouse/ button /was/ released. Do you know about the alternative?
      >
      b = Button(..., command=functio n) # no bind(), no lambda
      >
      It behaves like you expect.
      >
      Peter

      So, then is it right to say that for a widget like button widget on
      occurance of a 'event' the function which is bound to this event is
      invoked, even if the button widget has its 'state' option set to
      'disabled'. I was assuming that if the button widget has state =
      'disabled' then even on a button event the binding function wont be
      invoked.
      I will take a look at the alternative code you suggested above too.

      Thanks
      Rahul

      Comment

      • Gabriel Genellina

        #4
        Re: tkinter button state = DISABLED

        En Mon, 14 May 2007 17:46:32 -0300, <rahulnag22@yah oo.comescribió:
        On May 14, 12:01 pm, Peter Otten <__pete...@web. dewrote:
        >rahulna...@yah oo.com wrote:
        b=Button(frame, text = "Button", state = 'disabled')
        b.bind("<Button Release-1>",
        lambda
        event :
        function()
        )
        >>
        >Well, the /mouse/ button /was/ released. Do you know about the
        >alternative?
        >>
        >b = Button(..., command=functio n) # no bind(), no lambda
        >It behaves like you expect.
        >
        So, then is it right to say that for a widget like button widget on
        occurance of a 'event' the function which is bound to this event is
        invoked, even if the button widget has its 'state' option set to
        'disabled'. I was assuming that if the button widget has state =
        'disabled' then even on a button event the binding function wont be
        invoked.
        I will take a look at the alternative code you suggested above too.
        Maybe there is a confusion here. You code above means that, when the event
        "The leftmost MOUSE BUTTON was released" happens over your BUTTON WIDGET
        b, your function will be called.
        The "alternativ e code" suggested is the right way; the "command" is fired
        when the mouse button is pressed inside the widget AND then released
        inside the SAME widget (and the button is not disabled).

        --
        Gabriel Genellina

        Comment

        • James Stroud

          #5
          Re: tkinter button state = DISABLED

          rahulnag22@yaho o.com wrote:
          I have created a button widget with a button click binding. The button
          initially has a state=disabled. I can see the greyed out version of
          the button in the GUI. But If I click on the button it still invokes
          the callback/binding function.
          >
          Any suggestions as to why the callback is being invoked even though
          the button has a disabled state. It looks like-
          >
          b=Button(frame, text = "Button", state = 'disabled')
          >
          b.bind("<Button Release-1>",
          lambda
          event :
          function()
          )
          >
          Thanks
          Rahul
          >
          DISABLED refers to the whether the function supplied in the "command"
          parameter is called when the button is pressed, other bindings are
          irrelevant, so you will need code to re-bind any events you have bound
          when the button is "disabled". So its better to just use the "command"
          parameter rather than binding mouse events.

          An exception is Checkbutton, where you might want to bind
          <ButtonReleas e-1and then query the button's state (or the state of an
          IntVar associated with it) to make a decision--if you want a GUI to
          respond real-time to user events.

          James

          Comment

          • Hendrik van Rooyen

            #6
            Re: tkinter button state = DISABLED

            "Gabriel Genellina" <gagsl-py2@yahoo.com.a rwrote:
            >Maybe there is a confusion here. You code above means that, when the event
            >"The leftmost MOUSE BUTTON was released" happens over your BUTTON WIDGET
            >b, your function will be called.
            I have never seen this working in Tkinter, unless the button was pressed on the
            widget
            in question - and worse, once you have clicked down on a ButtonRelease binding
            you can move the mouse pointer anywhere you like, even out of the application
            and when you release it, the bound function is called...

            Its either a bug or a feature, I don't know.

            - Hendrik





            Comment

            • Gabriel Genellina

              #7
              Re: tkinter button state = DISABLED

              En Wed, 16 May 2007 03:22:17 -0300, Hendrik van Rooyen
              <mail@microcorp .co.zaescribió:
              "Gabriel Genellina" <gagsl-py2@yahoo.com.a rwrote:
              >
              >Maybe there is a confusion here. You code above means that, when the
              >event
              >"The leftmost MOUSE BUTTON was released" happens over your BUTTON WIDGET
              >b, your function will be called.
              >
              I have never seen this working in Tkinter, unless the button was pressed
              on the
              widget
              in question - and worse, once you have clicked down on a ButtonRelease
              binding
              you can move the mouse pointer anywhere you like, even out of the
              application
              and when you release it, the bound function is called...
              >
              Its either a bug or a feature, I don't know.
              Uhmm... I'm not sure I understand you completely. I only said that the
              "command" is fired only when the mouse button is pressed on the widget,
              AND released inside the same widget. If both events don't happen in the
              same widget, "command" won't fire. Maybe you are saying the same thing...
              anyway I'm not a Tk expert.

              --
              Gabriel Genellina

              Comment

              • Hendrik van Rooyen

                #8
                Re: tkinter button state = DISABLED

                "Gabriel Genellina" <gagsl-py2@yahoo.com.a rwrote:

                >En Wed, 16 May 2007 03:22:17 -0300, Hendrik van Rooyen
                ><mail@microcor p.co.zaescribió :
                >
                > "Gabriel Genellina" <gagsl-py2@yahoo.com.a rwrote:
                >>
                >>Maybe there is a confusion here. You code above means that, when the
                >>event
                >>"The leftmost MOUSE BUTTON was released" happens over your BUTTON WIDGET
                >>b, your function will be called.
                >>
                >I have never seen this working in Tkinter, unless the button was pressed
                >on the
                >widget
                >in question - and worse, once you have clicked down on a ButtonRelease
                >binding
                >you can move the mouse pointer anywhere you like, even out of the
                >application
                >and when you release it, the bound function is called...
                >>
                >Its either a bug or a feature, I don't know.
                >
                >Uhmm... I'm not sure I understand you completely. I only said that the
                >"command" is fired only when the mouse button is pressed on the widget,
                >AND released inside the same widget. If both events don't happen in the
                >same widget, "command" won't fire. Maybe you are saying the same thing...
                >anyway I'm not a Tk expert.
                No command is ok and you have described it right - its ButtonRelease that
                seems broken to me

                - Hendrik

                Comment

                • Eric Brunel

                  #9
                  Re: tkinter button state = DISABLED

                  On Thu, 17 May 2007 09:30:57 +0200, Hendrik van Rooyen
                  <mail@microcorp .co.zawrote:
                  "Gabriel Genellina" <gagsl-py2@yahoo.com.a rwrote:
                  >En Wed, 16 May 2007 03:22:17 -0300, Hendrik van Rooyen
                  >>I have never seen this working in Tkinter, unless the button was
                  >>pressed
                  >>on the
                  >>widget
                  >>in question - and worse, once you have clicked down on a ButtonRelease
                  >>binding
                  >>you can move the mouse pointer anywhere you like, even out of the
                  >>application
                  >>and when you release it, the bound function is called...
                  >>>
                  >>Its either a bug or a feature, I don't know.
                  >>
                  >Uhmm... I'm not sure I understand you completely. I only said that the
                  >"command" is fired only when the mouse button is pressed on the widget,
                  >AND released inside the same widget. If both events don't happen in the
                  >same widget, "command" won't fire. Maybe you are saying the same
                  >thing...
                  >anyway I'm not a Tk expert.
                  >
                  No command is ok and you have described it right - its ButtonRelease that
                  seems broken to me
                  Apparently, this behaviour is the intended one, at least for buttons; see:


                  As for the question "why?", maybe you should ask it on the c.l.tcl
                  newsgroup?
                  --
                  python -c "print ''.join([chr(154 - ord(c)) for c in
                  'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"

                  Comment

                  Working...