M.Jones M.Jones - 6 months ago 3
Python Question

using queue to add a shape in canvas

I was confused on how to add a shape using a queue in canvas. I'm trying to add a triangle. This is the code I've got. I'm getting an error >>> AttributeError: 'Queue' object has no attribute 'enqueue'

I've been trying this for awhile now and I thought I had the right idea, I just need some guidelines thanks!

from tkinter import *
import random
root = Tk()
from queue import *

class Queue:
def __init__(self):
self.items = []
def is_empty(self):
return self.items == []
def size(self):
return len(self.items)
def enqueue(self, item):
self.items.insert(0, item)
def dequeue(self):
return self.items.pop(0)
def peek(self):
return self.items[0]

class Recta():
def __init__(self, height=60, width=80):
self.queue = Queue()

def create_buttons(self):
self.button5 = Button(self.frame, text = "Add Arc", command = self.random_arc)
self.button5.pack(side = 'left')

def random_arc(self):
w = random.randrange(45)
h = random.randrange(90)
self.queue.enqueue(self.canvas.create_arc(0,w,h,fill= "green"))

tes = Recta()
tes = Queue()


For the module queue I don't see a function enqueue().

There is queue.Queue.put(), though.


Is it possible, that python is taking the "wrong" Queue, meaning the one from inside the module queue?


Maybe start by renaming your class "Queue" to something different like "Queue1".

Or just use the queue.Queue from the module.