중히 여기다:
from Tkinter import *
a = Tk()
canvas = Canvas(a, width = 500, height = 500)
canvas.pack()
canvas.create_rectangle(0, 0, 100, 100)
생성 된이 사각형을 어떻게 삭제합니까?
이것은 내가 만드는 게임과 관련이 있습니다. 공이 블록을 치면 블록이 사라지는 간단한 게임입니다. 하지만 이렇게하면 :
class Block:
def __init__(self,canvas,color):
self.canvas = canvas
self.id = canvas.create_rectangle(10, 10, 110, 20, fill=color )
self.id1 = canvas.create_rectangle(115, 10, 215, 20, fill=color)
self.id2 = canvas.create_rectangle(220, 10, 320, 20, fill=color)
self.id3 = canvas.create_rectangle(325, 10, 425, 20, fill=color)
self.id4 = canvas.create_rectangle(430, 10, 530, 20, fill=color)
self.id5 = canvas.create_rectangle(100, 150, 200, 160, fill=color)
self.id6 = canvas.create_rectangle(350, 150, 450, 160, fill=color)
self.x = 0
그리고:
def hit_block(self,pos):
block_pos = self.canvas.coords(self.block.id)
List = [block_pos]
for i in List:
if pos[0] >= i[0] and pos[2] <= i[2]:
if pos[1] >= i[1] and pos[1] <= i[3]:
canvas.delete(block.id)
self.score()
global a
a += 1
return True
return False
작동하지 않습니다. 공이 맞았을 때 블록을 삭제하려면 어떻게해야합니까?
create_rectangle()
변수에를 할당 한 다음 canvas.delete()
해당 변수 를 호출 합니다.
from Tkinter import *
a = Tk()
canvas = Canvas(a, width = 500, height = 500)
canvas.pack()
myrect = canvas.create_rectangle(0,0,100,100)
canvas.delete(myrect) #Deletes the rectangle
삭제 전 창 :
삭제 후 창 :
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다