

# https://www.globalsino.com/ICs/page4853.html
# Turn on and off with mouse press


from threading import Thread
from tkinter import *

running = False
My_popup = Tk()
My_popup.title('Popup window')
My_popup.geometry('200x100')

def press_mouse(event):
    global running
    running = True

def release_mouse(event):
    global running
    running = False
    print("\nYou released the mouse.")

def Clicking_mouse():
    while True:
        if running:
            print("You are pressing the left mouse.")

my_button = Button(My_popup, text ="Press me!")
my_button.pack()
my_button.bind('<ButtonPress-1>',press_mouse)
my_button.bind('<ButtonRelease-1>',release_mouse)

# Create and start the new thread to use its attribute 'start'
# but the module of Thread is not really used.
Thread(target = Clicking_mouse, args = ()).start() # Thread()

My_popup.mainloop()
