我试图从我的程序中删除列表堆栈和队列中橙色的所有对象,目前在如何从我的代码进展方面遇到困难,只需要了解如何启动它恰当。我尝试了一下,但似乎只是在创造更多的形状。任何帮助都会非常感谢!
from tkinter import *
import random
root = Tk()
from Stack import Stack
from my_queue import *
class Recta:
def __init__(self, height=60, width=80 ,colours= []):
self.height = height
self.width = width
self.canvas = Canvas(root)
self.canvas.pack()
self.colours = ["red", "orange"]
self.rects = []
self.stack = Stack()
self.queue = Queue()
def randomCircle(self):
w = random.randrange(300)
h = random.randrange(200)
self.stack.push(self.canvas.create_oval(0,0,w,h,fill= random.choice(self.colours)))
def randomRects(self):
w = random.randrange(300)
h = random.randrange(200)
self.rects.append(self.canvas.create_rectangle(0, 0, w, h, fill= random.choice(self.colours)))
def random_arc(self):
x1 = random.randrange(300)
y1 = random.randrange(200)
x2 = random.randrange(300)
y2 = random.randrange(200)
e = random.randrange(90)
s = 45 + ( 90 -e)/2
self.queue.enqueue(self.canvas.create_arc( x1, y1, x2, y2 ,start=s,extent=e,fill= random.choice(self.colours)))
def remove_all_orange_shapes(self):
if self.randomRects() == "orange":
self.canvas.delete(self.rects.pop())
elif self.randomCircle() == "orange":
self.canvas.delete(self.stack.pop())
elif self.random_arc() == "orange":
self.canvas.delete(self.queue.dequeue())
tes = Recta()
tes= Stack()
tes = Queue()
root.mainloop()