Hỏi đáp

Chia sẻ kiến thức, cùng nhau phát triển

python lập trình game chơi bóng

3 năm trước 1.048 lượt xem 0 bình luận

Cho mình hỏi khi mình viết đoạn code game đỡ bóng trên python

from tkinter import *
import time
import random

class Ball:
    def __init__(seft, canvas, color):
        seft.canvas = canvas
        seft.id = canvas.create_oval(10, 10, 25, 25, fill=color)
        seft.canvas.move(seft.id , 100, 200)
        def draw(seft):
            seft.canvas.move(seft.id, -1, 0)

tk= Tk()
tk.title("Game for you")
tk.resizable(0, 1)
can = Canvas(tk, width= 400, height = 500)
can.pack()

bong = Ball(can, "red")
while 1:
    bong.draw() [x.   File "C:\Users\****\Videos\New folder\python\định nghĩa trong python\gamedobong.py", line 21, in <module>
    bong.draw()
AttributeError: 'Ball' object has no attribute 'draw']

    tk.update_idletasks()
    tk.update()
    time.sleep(0.01)
tới dòng này thì báo lỗi :

Traceback (most recent call last):
  File "C:\Users\****\Videos\New folder\python\định nghĩa trong python\gamedobong.py", line 21, in <module>
    bong.draw()
AttributeError: 'Ball' object has no attribute 'draw'

Là sao vậy mọi người? Xin cách sửa lỗi

Bình luận

Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.

Đăng nhập