python - 向变量添加坐标
问题描述
我正在尝试创建一个程序,您可以在其中尽可能快地按下某些坐标。如果这里有人知道我的世界,我有一个箱子的截图,并且正在尝试实施,你必须点击箱子里的好物品。这就是为什么我需要访问胸部插槽坐标的原因。这是代码:
import tkinter as tk
from PIL import ImageTk, Image
window = tk.Tk()
window.title("Chest Simulator")
window.geometry("1920x1080")
window.configure(background='grey')
path = "chest.jpg"
Chest1
img = ImageTk.PhotoImage(Image.open(path))
panel = tk.Label(window, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
window.mainloop()
如果有人可以在这里帮助我,谢谢
解决方案
您可以使用 tkinter.bind()
函数,然后在该函数内部检查单击的坐标是否在您的项目范围内。
对于物品类别,您必须输入物品命中框的左下角和右上角。单击后,hititems 列表将填充单击的项目。不要忘记在每次运行后清除它。
class item:
def __init__(self,startx,starty,endx,endy):
self.startx=startx
self.starty=starty
self.endx=endx
self.endy=endy
items=[item(),item()...] #add your coordinates inside here
hititems=[]
def click(event):
global items
global hititems
for i in items:
if i.endy>=event.y>=i.starty and i.endx>=event.x>=i.startx:
hititems.append(i)
panel.bind("<button1>",click)
推荐阅读
- laravel - Laravel 生成基本身份验证
- java - 找不到 Spring Bean
- javascript - 如何在浏览器中将 m3u8 URL 转换为 mp4 可下载文件?
- c - 我为 Visual Studio 代码安装了 vcpkg-master 并安装了他们的包,之后只有我的 Clion 停止工作
- css - VSCode 智能感知充斥着 typescript 中的 css 类
- go - 类型与 []byte 属性上的投影不匹配
- javascript - 电子工作者:隐藏的 BrowserWindow 导致前端滞后
- bash - Bash 脚本:如何从文件中读取作为参数传递的行,并将其存储在变量中
- android - 如何将经过的时间从现在转换为该日期并将该方法传递给kotlin中的viewholder
- javascript - Laravel - Ajax 调用时出现 500(内部服务器错误)