python编程-14:tkinter绘制接收事件的图形_彭世瑜_新浪博客
【摘要】
源码:
from tkinter import * def main(): tk = Tk() canvas =&nbs...
源码:
- from tkinter import *
- def main():
- tk = Tk()
- canvas = Canvas(tk, width = 400, height = 400)
- canvas.pack()
- def moverectangle(event):
- if event.keysym == "Up":
- canvas.move(1,0,-5)
- elif event.keysym == "Down":
- canvas.move(1,0,5)
- elif event.keysym == "Left":
- canvas.move(1,-5,0)
- elif event.keysym == "Right":
- canvas.move(1,5,0)
- canvas.create_rectangle(180,180,220,220,fill="red")
- canvas.bind_all("",moverectangle)
- canvas.bind_all("",moverectangle)
- canvas.bind_all("",moverectangle)
- canvas.bind_all("",moverectangle)
- if __name__ == '__main__':
- main()
文章来源: pengshiyu.blog.csdn.net,作者:彭世瑜,版权归原作者所有,如需转载,请联系作者。
原文链接:pengshiyu.blog.csdn.net/article/details/109661680
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)