Ai
1 Star 0 Fork 0

我在吃大西瓜呢/Python课程学习

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ex5_x1.py 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
我在吃大西瓜呢 提交于 2020-04-01 16:05 +08:00 . second commit
#__*__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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wang_ming_er/python_course_learning.git
git@gitee.com:wang_ming_er/python_course_learning.git
wang_ming_er
python_course_learning
Python课程学习
master

搜索帮助