disabling button

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

    disabling button

    using tkinter i created a gui and put a button on the frame

    class mygui:
    def __init__(self, parent):
    ...
    self.okButton = Button(self.btn Frame)
    self.okButton.c onfigure(width= somewdth,text=" OK",

    anchor=W,disabl edforeground="t an")
    self.okButton.b ind("<Button-1>",self.button 1Click)

    then in the buttonClick(sel f,event) i want to disable it till some
    time consuming calculations are completed ..then i enable it

    def button1Click(se lf, event):
    self.okButton.c onfigure(state= DISABLED)
    print "ok disabled"
    somebigcalculat ions()
    self.okButton.c onfigure(state= NORMAL)
    print "ok enabled"

    well,the button doesn't grey out when i click it ,though the print
    staements are executed..
    but if some error happens and program exits with some ioerror(say
    errno2 file not found ..)then the button is shown as greyed out..

    am i missing something here ? how can i get the button disabled and
    greyed out on clicking it?

    dn



  • Fredrik Lundh

    #2
    Re: disabling button

    devnew@gmail.co m wrote:
    then in the buttonClick(sel f,event) i want to disable it till some
    time consuming calculations are completed ..then i enable it
    >
    def button1Click(se lf, event):
    self.okButton.c onfigure(state= DISABLED)
    + self.okButton.u pdate_idletasks ()
    print "ok disabled"
    somebigcalculat ions()
    self.okButton.c onfigure(state= NORMAL)
    print "ok enabled"
    >
    well,the button doesn't grey out when i click it ,though the print
    staements are executed..
    but if some error happens and program exits with some ioerror(say
    errno2 file not found ..)then the button is shown as greyed out..
    >
    am i missing something here ? how can i get the button disabled and
    greyed out on clicking it?
    when Tkinter needs to redraw things, it adds the redraw action to an
    internal "task" queue. tasks in this queue are usually handled by the
    main event loop, but that loop doesn't run when you do your big
    calculations. an explicit call to "update_idletas ks" will clear out the
    task queue for you.

    </F>

    Comment

    • devnew@gmail.com

      #3
      Re: disabling button

      an explicit call to "update_idletas ks" will clear out the
      task queue for you.
      </F>
      it worked
      Thanks F.L!!
      dn

      Comment

      • damonjulian@yahoo.com

        #4
        Re: disabling button



        if you disable the button it can still respond to clicks? it only
        greys out.. or is there a problem with my code here?

        class MyApp:
        def __init__(self,p arent):
        self.mainframe= Frame(parent)
        self.mainframe. pack()


        self.button1=Bu tton(self.mainf rame,bg="green" )
        self.button1.co nfigure(text="1 ")
        self.button1.pa ck(side=LEFT)
        self.button1.bi nd("<Button-1>",self.button Click1)
        self.button2=Bu tton(self.mainf rame,bg="yellow ")
        self.button2.co nfigure(text="2 ")
        self.button2.pa ck(side=LEFT)
        self.button2.bi nd("<Button-1>",self.button Click2)
        self.button3=Bu tton(self.mainf rame,bg="red")
        self.button3.co nfigure(text="3 ")
        self.button3.pa ck(side=RIGHT)
        self.button3.bi nd("<Button-1>",self.button Click3)

        def buttonClick1(se lf,event):
        print "ok clicked"
        self.button2.co nfigure(state=D ISABLED)
        self.button2.up date_idletasks( )

        def buttonClick2(se lf,event):
        print "2 clicked"

        def buttonClick3(se lf,event):
        print "3 clicked"
        self.button2.co nfigure(state=N ORMAL)
        #self.button2.u pdate_idletasks ()



        root = Tk()
        myapp = MyApp(root)
        root.mainloop()


        here when u click button 1 ,the button2 greys out but can still
        respond to clicks..is there a way to truly disable it?

        damon

        Comment

        Working...