如何获取运动部件在特定点的坐标?

问题描述 投票:0回答:1

我想模拟智能测速摄像头。 我放置了汽车的照片并启动了它。 我希望在到达某个点(相机位置)时记录速度。 问题是当汽车到达摄像头时我无法获取汽车的位置。 我是 Python 和 Tkinter 的初学者。

from tkinter import *
import time
import random
w = 800
h = 600

window = Tk()
window.title("Drawing and Move")
window.geometry('800x600')
window.resizable(width=False , height=False)

canvas = Canvas(window, width=w, height=h)
canvas.place(x=10 , y=10)
canvas1 = Canvas(window, width=w, height=h)
canvas1.place(x=10 , y=60)
canvas2 = Canvas(window, width=w, height=h)
canvas2.place(x=10 , y=110)


car_img = PhotoImage(file="images.gif")
car = canvas.create_image(10,10,anchor=NW, image=car_img)
car1 = canvas1.create_image(10,10,anchor=NW, image=car_img)
car2 = canvas2.create_image(10,10,anchor=NW, image=car_img)

cam_img = PhotoImage(file="cctv.gif")
camera = Label(window,image=cam_img)
camera.place(x= 400,y=200)



while True:

    canvas.move(car, random.randrange(1,10),0)
    canvas1.move(car1,random.randrange(1,10),0)
    canvas2.move(car2,random.randrange(1,10),0)

    window.update()
    time.sleep(0.01)

window.mainloop()



tkinter coordinates tkinter-canvas
1个回答
0
投票

尝试在您的汽车上使用

print("")
,并将其设置为在您想要的时间进行打印。 另外,您声明了两个变量; w 和 h,其值为 600 和 800。然而,您使用了几何方法并手动输入,而您可以输入
window.geometry(f"{w}x{h}")
。只是指出这一点。

我可能是错的,因为我也是 Tkinter 的初学者,但使用常规的 Python 命令行可以做到这一点。

© www.soinside.com 2019 - 2024. All rights reserved.