0

I am developing an application where I have to detect an widget, get its coordinates and draw a rectangle around it. When user click on widget next screen will come and I have to repeat whole process. I have coordinates, and able to draw rectangle using Tkinter but the issue is that my code is being stuck in root.mainloop(). The code for creating tkinter transparent window:

class Application:
    def __init__(self,master, coordinates):
        
        self.master = master
        self.coordinates= coordinates
        self.master.overrideredirect(True)
        self.master.wm_attributes("-topmost", True)
        self.master.wm_attributes("-disabled", True)
        self.master.wm_attributes("-transparentcolor", "white")
        self.create_widgets()
        
    def create_widgets(self):
        w= Canvas(self.master , bg = "white", bd=0, highlightthickness=0)
        w.create_rectangle(self.coordinates[0],self.coordinates[1],100,100)
        w.pack()

In main() of another file I am calling

root = tk.Tk()
//coordinates is global list in which coordinates of widget is being set
app = Application(root,coordinates)
//in case if user change screen size, to updates the rectangle coordinates
root.after(1000, do_bold1)
root.mainloop()
//this function is detecting if screen has changed, if changed tkinter window will be hidden, then detecting coordinates again it will be displayed.
is_change= detect_screen()

From threading examples, I got root.mainloop() runs on main thread but how can I run these processes in parallel?

Anoosha
  • 11
  • 3
  • you should run only one `mainloop()`. And only one `Tk()`. And it should run in main thread. And it should use other widgets only in main thread. For other windows you should use Toplevel`. If you have to run two `mainloop` and two `Tk` (two separated programs) then you may use `multiprocessing` instead of `threads` and they will work as separated programs but they will need `Queue` send share data - and it makes other problems. – furas Dec 23 '20 at 02:22
  • instead of threads you should try to use `after()` to execute function periodically. – furas Dec 23 '20 at 02:23

0 Answers0