用鼠标指针操作小鸟去收集金币的一个例子。
from tkinter import * from random import randint def follow(event): cv.coords(bird,event.x,event.y) x1,y1,x2,y2 = cv.bbox(bird) items = cv.find_overlapping(x1,y1,x2,y2) for item in items: if item==bird:continue cv.delete(item) root = Tk() cv = Canvas(root,width=800,height=600,bg='lightblue') cv.pack() coin_image = PhotoImage(file='coin.png') coins = [] for c in range(100): x = randint(0,800) y = randint(0,600) co = cv.create_image(x,y,image=coin_image) coins.append(co)需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)
发表评论