代码拉取完成,页面将自动刷新
#__*__coding:utf-8__*__
#python3
import time
from tkinter import *
def moveImage(event):#图片logo.gif的移动要绑定的函数
if event.keysym=='Up':
canvas.move(1,0,-3)#移动ID为1的事物,使得横坐标加0,纵坐标减3
elif event.keysym=='Down':
canvas.move(1,0,+3)
elif event.keysym=='Left':
canvas.move(1,-3,0)
elif event.keysym=='Right':
canvas.move(1,3,0)
tk.update()
time.sleep(0.05)
def changeColor(event):
if event.keysym=='Up':
canvas.itemconfig(pg,fill='blue')#填充ID为pg的事物,填充为blue
tk=Tk()#窗口
canvas=Canvas(tk,width=400,height=400)#画布
canvas.pack()#显示出来
myImage=PhotoImage(file='D:\\pytest\\logo.gif')#图片格式必须为gif格式
im=canvas.create_image(0,0,anchor=NW,image=myImage)#加载图片
pg=canvas.create_polygon(10,10,10,60,50,35,fill='red')#创建三角形
print (im);print (pg) #显示图片和三角形的ID
canvas.bind_all('<KeyPress-Up>',moveImage)#绑定方向键 up
canvas.bind_all('<KeyPress-Down>',moveImage)
canvas.bind_all('<KeyPress-Left>',moveImage)
canvas.bind_all('<KeyPress-Right>',moveImage)
#canvas.bind_all('<KeyPress-Up>',changeColor)
tk.mainloop()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。