0

I got the source code of a timer that synchronizes with the timer of a videogame bomb but the problem is, when I'm playing the game and move my mouse and click it, I accidentally click the Timer UI and it makes the command prompt where the script is running pop up and it's really gamebreaking.

I was wondering if there's any way to make the UI clicktrough so even if I click it accidently the application does not pop up.

Here's the UI's code:

import tkinter as tkr

from python_imagesearch.imagesearch import imagesearch

root = tkr.Tk()
root.geometry("+0+0")
root.overrideredirect(True)
root.wm_attributes("-topmost", True)
root.wm_attributes("-alpha", 0.01)
root.resizable(0, 0)

timer_display = tkr.Label(root, font=('Trebuchet MS', 30, 'bold'), bg='black')
timer_display.pack()

seconds = 44

//in this space i print a lot of lines creating a box with text explaining what the script does in it.

def countdown(time):
    if time > 0:
        mins, secs = divmod(time, 60)

        ID = timer_display.bind('<ButtonRelease-1>', on_click)
        timer_display.unbind('<ButtonRelease-1>', ID)
        def color_change(t_time):
            if t_time > 10:
                return 'green'
            elif 7 <= t_time <= 10:
                return 'yellow'
            elif t_time < 7:
                return 'red'

        timer_display.config(text="{:02d}:{:02d}".format(mins, secs),
                             fg=color_change(time)), root.after(1000, countdown, time - 1)
    else:
        root.wm_attributes('-alpha', 0.01)
        search_image()


def start_countdown():
    root.wm_attributes('-alpha', 0.7)
    countdown(seconds)


def search_image():
    pos = imagesearch("./github.png")
    pos1 = imagesearch("./github1.png")
    if pos[0] & pos1[0] != -1:
        start_countdown()
    else:
        root.after(100, search_image)


root.after(100, search_image)
root.mainloop()
Hoekane
  • 3
  • 2

1 Answers1

0

If the UI you are talking about is timer_display then I suppose you are using bind function for the clicking part you were talking about. Here is what you can try:

# Save the binding ID
ID = timer_display.bind('<ButtonRelease-1>', on_click)

Then use it to unbind <ButtonRelease-1>

timer_display.unbind('<ButtonRelease-1>', ID)

Maybe this question might be of some help.

Blake
  • 28
  • 2
  • 10
  • Hey, i updated the post and updated the code so now it's complete, what it does is it detects images i took of the game when it displays that the bomb has been planted for it to scan for the image pixels In-Game and start a counter if it detected it successfully heres an image of what it looks like: https://prnt.sc/1106k77 The problem here is when i move my mouse to look around In-Game my mouse pointer goes over the overlay timer and i accidentally click on it and selects the script process, this is because i need to run the game on Fullscreen Windowed or else it wont show, is there any way? – Hoekane Mar 30 '21 at 21:16