1
class simpleapp_tk(tkinter.Tk):
    def __init__(self,parent):
        tkinter.Tk.__init__(self,parent)
        self.parent = parent
        self.initialize()



    def initialize(self):
        self.grid()
        self.ZOOMIN = tkinter.Button(self,text="ZOOM IN")
        self.ZOOMIN.grid(column=1,row=6)
        self.ZOOMIN.bind("<Button-1>",self.bzoomin())
        self.ZOOMIN.bind("<ButtonRelease-1>", self.brzoomin())

        self.pollvar=0


    def poll(self):
        if self.pollvar==1:
            self.ZOOMIN.after(300,self.poll())
            self.OnZOOMINClick()


    def brzoomin(self,event):
        self.pollvar=0
    def bzoomin(self,event):
        self.pollvar=1
        self.poll


    def OnZOOMINClick(self):
    ....code


if __name__ == "__main__":
    app = simpleapp_tk(None)
    app.title('CAMERA CONTROLL v1')

    app.mainloop()

I am trying to make a function to be repeatedly called while mousebutton-1 is pressed on the zoominbutton. This is supposed to be implemented through polling. When the button is clicked the poll function should be called. The poll should run continously untill mousebutton-1 is released. But the problem is that nothing happens when the button is pressed.

Edited the errors pointed out. But there must still be some problem with the code as the window itself doesn't show anymore and the code goes into an infinite loop because of the line "self.ZOOMIN.after(300,self.poll())". (This is just a part of my code)

1
  • If you plan on writing (and sharing) a lot of python code, you might want to consider reading PEP 8. It recommends using names_with_underscores for methods and reserving CamelCase for classes (among other things). Commented Aug 27, 2012 at 14:58

1 Answer 1

2

In python, you need to actually call a method/function by using parenthesis to pass a series of arguments. If the function/method accepts no arguments, you still need empty parenthesis. In other words, you want:

self.poll()

and

self.OnZOOMINClick()
self.grid()

instead of self.poll, self.OnZOOMINClick, and self.grid etc. This is because in python, functions and methods are objects. They can be passed to functions or bound to local variables just like anything else.

There might be other bugs here, but those stand out right away (your rows and columns in your .grid methods seem a little weird too if you're showing all of the code.) One other bug which sticks out is that the definition of OnZOOMINClick should probably be def OnZOOMINClick(self).


Also note that self.pollvar = int() and self.pollvar = 0 do the exact same thing and you only need one of the two statements (I would prefer the latter).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.