私のプログラムは動作しません。男は動くつもりなのですが、きちんと表示することさえできません。助けてください私のコードは...
from tkinter import *
import random
import time
class Paddle:
def __init__(self, canvas):
self.canvas = canvas
my_image = PhotoImage(file='C:\\Documents and Settings\\Patrick\\Desktop\\ most commonly used stuff\\game\\bob 1.GIF')
self.id = canvas.create_image(0, 0, image=my_image)
self.canvas.move(self.id, 200, 300)
self.x = 0
self.id.pack()
def left(self, evt):
print('Left')
self.x = -2
canvas.move(self.id, 10, 0)
def right(self, evt):
print('Right')
self.x = 2
canvas.move(self.id, -10, -0)
def up(self, evt):
self.x = 2
canvas.move(self.id, -0, -10)
def down(self, evt):
self.x = 2
canvas.move(self.id, -0, 10)
def draw(self):
self.canvas.move(self.id, self.x, 0)
pos = self.canvas.coords(self.id)
if pos[0] <= 0:
self.x = 0
elif pos [2] >= self.canvas_width:
self.x = 10
def easy():
paddle = Paddle(canvas,)
tk.bind("<KeyPress-Right>", paddle.left)
tk.bind("<KeyPress-Left>", paddle.right)
tk.bind("<KeyPress-a>", paddle.right)
tk.bind("<KeyPress-d>", paddle.left)
tk.bind("<KeyPress-Up>", paddle.up)
tk.bind("<KeyPress-Down>", paddle.down)
b2.destroy()
while 1:
tk.update_idletasks()
tk.update()
time.sleep(0.01)
def start():
b2.pack()
b.destroy()
tk = Tk()
tk.title("game")
tk.resizable(0, 0)
tk.wm_attributes("-topmost", 1)
canvas = Canvas(tk, bg="yellow", width=500, height=400)
canvas.pack()
tk.update
b = Button(tk, text="play", command=start)
b.pack()
b2 = Button(tk, text="easy", command=easy)
console = ['top','bottom','right','left','paddle']
私は本当にこれが機能することを望んでおり、助けてくれた人のおかげで誰かがそれを修正してくれたら本当にありがたいです:)