我得到了一个计时器的源代码,它与一个视频游戏炸弹的计时器同步,但问题是,当我玩游戏并移动鼠标并单击它时,我不小心单击了计时器用户界面,它会弹出脚本运行的命令提示符,这真的是游戏崩溃
我想知道是否有任何方法可以让用户界面通过点击,这样即使我不小心点击了它,应用程序也不会弹出
以下是UI的代码:
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()
如果您正在谈论的UI是
timer_display
,那么我假设您正在使用bind
函数来处理您正在谈论的单击部分。以下是您可以尝试的内容:然后使用它解除绑定
<ButtonRelease-1>
也许这个question会有所帮助
相关问题 更多 >
编程相关推荐