猫史档案馆


【Python作品分享】我的文件-副本【作品秀】

用户:何祖文何祖文查看:0 回复:1 评论:0 创建时间:2022-04-04T20:53:55


【作品展示】

center_image

 

【作品介绍】

做出了弹跳,哈哈哈哈\(^o^)/~

 

【作品源代码】

from tkinter import *
import random
import time


class Ball:
    def __init__(self, canvas, color):
        self.canvas = canvas
        self.ide = canvas.create_oval(10, 10, 25, 25, fill=color)
        self.canvas.move(self.ide, 245, 100)
        self.x = 0
        self.y = -1
        self.canvas_height = self.canvas.winfo_height()

    def draw(self):
        self.canvas.move(self.ide, self.x, self.y)
        pos = self.canvas.coords(self.ide)
        if pos[1] <= 0:
            self.y = 1
        if pos[3] >= self.canvas_height:
            self.y = -1


root = Tk()
root.title("game")
root.resizable(0, 0)
root.wm_attributes("-topmost", 1)
canvas = Canvas(width=500, height=400, bd=0, highlightthickness=0)
canvas.pack()
canvas.update()

ball = Ball(canvas, 'red')
while 1:
    ball.draw()
    root.update_idletasks()
    root.update()
    time.sleep(0.01)

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
WP40WP40

不错不错!

点赞0


评论