猫史档案馆


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

用户:何祖文何祖文查看:0 回复:0 评论:0 创建时间:2022-04-05T10:24:25


【作品展示】

center_image

 

【作品介绍】

hhhhh

 

【作品源代码】

try:
    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)
            starts = [-3, -2, -1, 1, 2, 3]
            random.shuffle(starts)
            self.x = starts[0]
            self.y = -2
            self.canvas_height = self.canvas.winfo_height()
            self.canvas_width = self.canvas.winfo_width()

        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
            if pos[0] <= 0:
                self.x = 2
            if pos[2] >= self.canvas_width:
                self.x = -2

    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)
except:
    print("出错了")

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页