0

Hi guys hope you are doing well, please help me i have this simple program you can try and run it that prints as output the hexadecimal value of the colour that the cursor is pointing, but the windows doesn't even get created

import PIL.ImageGrab
from tkinter import *
from pynput.mouse import Controller, Listener
window = Tk()
window.title("Colore in esadecimale")
window.call('wm', 'iconphoto', window._w, PhotoImage(file="trasparente.png"))
window.geometry("500x250")
window.resizable(width=False, height=False)
window.configure(bg="#3C3F41")
etichetta_titolo_valore = Label(window,text="Valore",font=("Ink Free",20),bg="#3C3F41",fg="white")
etichetta_titolo_valore.pack(pady=(20,0))
etichetta_valore = Label(window,text="ciao",font=("Ink Free",20),bg="#3C3F41",fg="white")
etichetta_valore.pack(pady=(10,0))
def mouse_move(x, y):
    try:
        rgb = PIL.ImageGrab.grab().load()[x, y]
        rgb = '#%02x%02x%02x' % (rgb)
        rgb = rgb.upper()
        print(rgb)
    except(IndexError):
        pass
with Listener (on_move = mouse_move) as listener:
    listener.join()
window.mainloop()
  • Do the answers to this [question](https://stackoverflow.com/questions/56871975/how-to-run-pynput-listener-simultaneously-with-tkinter-tk-mainloop) help at all? – quamrana Jun 06 '22 at 08:48
  • tkinter provides its own mouse tracking via event binding. Do a research on *tkinter bind motion*. – Thingamabobs Jun 06 '22 at 08:49
  • @Thingamabobs Hi, yes i can use window.bind("",mouse_move) But this detect's the movement of the mouse only inside the tkinter window, i want to detect the movement of the mouse on the all screen, all the area in my monitor not only the area in the program, could you help me? – Forty966699669 Jun 06 '22 at 08:53
  • @quamrana Hi, yes i can use window.bind("",mouse_move) But this detect's the movement of the mouse only inside the tkinter window, i want to detect the movement of the mouse on the all screen, all the area in my monitor not only the area in the program, could you help me? – Forty966699669 Jun 06 '22 at 08:53
  • 1
    No, I can't help you, but the answers to the question I linked to may help. They were not all about `window.bind()`. – quamrana Jun 06 '22 at 09:03
  • Ok @quamrana your first answer helped me, but now when i close the window i have this error RuntimeError: main thread is not in main loop, and it's very annoying because the cursor frame drops, you can try, how to solve? I updated my question with the updated code – Forty966699669 Jun 06 '22 at 09:37
  • I'm sorry, but stackoverflow is not your personal software development environment. You should revert your edit back to your original code and ask a brand new question with your latest code. The original question may help future programmers searching for the same thing. (As may your next question). – quamrana Jun 06 '22 at 09:40
  • @quamrana Ok i re edited the question, i did that in order to not create an other question for just an adjustment, in order to not fill the site with a lot of questions – Forty966699669 Jun 06 '22 at 09:44
  • So, did you find a solution to your original question from one of the comments? – quamrana Jun 06 '22 at 09:46
  • @quamrana yes the answer you linked me in your first question solved my problem thank you a lot at least now works, but now there are other 2 mini problems so i have to make an other question for them, as you said before – Forty966699669 Jun 06 '22 at 09:55
  • Ok, please go ahead and ask a brand new question. I can mark this as a duplicate of the one I linked to. – quamrana Jun 06 '22 at 09:57

0 Answers0