I have a problem, I was working on a code with python 3. the code is about getting news of a website onto my canvas. however I keep getting this error which says:
AttributeError: 'NewsFeed' object has no attribute 'canvas'.
this is my code:
from tkinter import *
import feedparser
root=Tk()
class Achtergrond() :
m_Width = 0
m_Height = 0
m_BgColor = 0
def CreateCanvas(self, master, width, height) :
m_Width = width
m_Height = height
m_BgColor='#14B4E1'
self.canvas = Canvas(master, width=m_Width, height=m_Height)
self.canvas.configure(bg=m_BgColor)
self.canvas.pack()
return(self.canvas)
def create_rectangle(x0, y0 ,x1,y1, color) :
self.canvas.create_rectangle(x0, y0, x1, y1, fill=color)
return
def create_title (self, x, y, title, opmaak):
self.canvas.create_text(x,y,text=title, font= opmaak)
return
def create_newsbox(master,x0,y0,x1,y1,color):
canvas.create_rectangle(x0,y0,x1,y1, fill=color)
return
def SetBackgroundColor(self, kleurcode) :
m_BgColor = kleurcode
self.canvas.configure(bg=m_BgCode)
self.canvas.pack()
return
class NewsFeed ():
Hitem = 0
Nitem = 0
feed = 0
th = 0
rssURL = ""
def UpdateNews(self,path):
self.rssURL = path
self.feed = feedparser.parse(self.rssURL)
self.Nitem = len(self.feed["items"])
return
def ToonEerste(self):
str=""
self.Hitem = 0
for i in range(self.Hitem,self.Hitem+2,1):
if i < self.Nitem:
entry = self.feed["entries"][i]
str += entry.title + "
" + entry.summary + "
__________________________________________________
"
self.canvas.delete(th)
th = self.canvas.create_text(200,300, width=300, text = str)
return
def ToonVolgende(self):
str=""
self.Hitem += 3
if self.Hitem >= self.Nitem:
Hitem = 0
for i in range(self.Hitem,self.Hitem+2,1):
if i < self.Nitem:
entry = feed["entries"][i]
str += entry.title + "
" + entry.summary + "
__________________________________________________
"
self.canvas.delete(th)
th = self.canvas.create_text(200,300, width=300, text = str)
return
hoofdscherm = Achtergrond()
a = hoofdscherm.CreateCanvas(root, 1024,600)
b = hoofdscherm.canvas.create_rectangle(30, 120, 360, 500, fill= '#ffffff')
a.create_rectangle(10,10, 1014,80, fill='#ffffff')
a.create_rectangle(30, 120, 360, 500, fill= '#ffffff')
a.create_text(250, 50, text="Harens Lyceum" , font=('Calibri' , 40))
a.configure(bg='#14B4E1')
a.pack()
n = NewsFeed()
n.UpdateNews('http://www.nu.nl/rss/Algemeen')
n.ToonEerste(root)
n.ToonVolgende(root)
root.mainloop()
We would like to have some help with our problem, we don't have much experience. We need to make a screen with raspberry which displays news etc. for school. If you know how we can fix our code we would very much appreciate your guys' help.
See Question&Answers more detail:
os