code.
1.) The function gets called at CV.mousecallback() and the program enters the while loops until the program ends so the function should only be called once but instead it is called on every mouse click.. how does this work? Does calling setmousecallback make it run on a parallel thread and continuously check for mouse clicks or something?
2.) Inside the function, variables are declared as global so the changes made in the scope of the function are also applied to the global variables, however img is also changed when rectangle or circle functions are called and the change is reflected globally even though img is not defined to use the global variable.. how does this work?
1.) I can't read that but if you bind a function to an event (like click) and want it to work only once and not every time you click, then at the end of the function unbind it. 2.) global variables are a headache, use classes that manage their own variables. It will be easier to figure out.
1. Yes, it runs on a different thread and creates new threads that executes the functions everytime a mouse click event happens. 2. img is used without initialization inside the function, the interpeter is smart enough to understand that you want the globaly defined img variable to be passed to the function call, the problem arises when you want to change the value of a parameter directly inside a function drawing = True; ix, iy = x, y the interpeter creates new variables in that case unless told otherwise.
Обсуждают сегодня