我是python新手,我想用鼠标左键移动图像,到目前为止,我有这个:
from tkinter import *
import pygame
root = Tk()
def callback(event):
if new.collidepoint(mouseposition):
canvas.move(new, 60,30)
canvas= Canvas(root, width=500, height=500)
canvas.pack(expand = YES, fill = BOTH)
new = PhotoImage(file = 'C:\\Users\\Andy\\Documents\\all pc
stuff\\Python\\CarPic.png')
canvas.create_image(50,10,image=new, anchor=NW)
canvas.bind("<Button-1>", callback)
canvas.pack()
root.mainloop()
但似乎有一个错误:
^{pr2}$我怎样才能解决这个问题?在
非常感谢!在
正如上面的@Brian Ton注释,您正试图在
tkinter.PhotoImage
对象上使用pygame.rect
方法。在如果您想在使用Tkinter时获得鼠标位置,this answer将有所帮助。在
如果你想使用pygame,这里有一个例子,在你点击鼠标的地方画一个正方形:
相关问题 更多 >
编程相关推荐