How about something like this. Code will update the self.headlineIndex
every X seconds (currently set to 1 second). The headline is grabbed using headline = feed['entries'][self.headlineIndex]['title']
. Notice the self.headlineIndex
inside the square braces rather than a number like zero.
try:
import tkinter as tk
except:
import Tkinter as tk
"""Some dummy data in the same format as OP"""
feed = {'entries': [{'title':"US Pres. incompetent"},
{'title':"Sport happened"},
{'title':"Politican Corrupt"}]
}
class App(tk.Frame):
def __init__(self,master=None,**kw):
tk.Frame.__init__(self,master=master,**kw)
self.txtHeadline = tk.StringVar()
self.headline = tk.Label(self,textvariable=self.txtHeadline)
self.headline.grid()
self.headlineIndex = 0
self.updateHeadline()
def updateHeadline(self):
try:
headline = feed['entries'][self.headlineIndex]['title']
except IndexError:
"""This will happen if we go beyond the end of the list of entries"""
self.headlineIndex = 0
headline = feed['entries'][self.headlineIndex]['title']
self.txtHeadline.set(headline)
self.headlineIndex += 1
self.after(1000,self.updateHeadline)
if __name__ == '__main__':
root = tk.Tk()
App(root).grid()
root.mainloop()