SirMongoose

Reddit API News Program

Jan 31st, 2016
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. import praw
  2. import tkinter as tk
  3. from tkinter import *
  4. refreshN = 0
  5.  
  6. def refresh():
  7.     global refreshN
  8.     text=[]
  9.     refreshN += 1
  10.     r = praw.Reddit(user_agent="windows:RedditNews_test:v1")
  11.     headlines = r.get_subreddit('askreddit').get_new(limit=10)
  12.     text = [str(x) for x in headlines]
  13.     canvas.create_rectangle(0,0,500,300,fill='#f2f2f2',outline='#f2f2f2')
  14.     for a in range(0,10):
  15.         canvas.create_text(15,a*30+15,text=str(a+1)+("."))
  16.         canvas.create_text(250,a*30+15,text=text[a])
  17.     print("Refreshed #"+str(refreshN))
  18.  
  19. root = tk.Tk()
  20. root.title("Reddit News")
  21. canvas = Canvas(root,width=500,height=330)
  22. canvas.grid()
  23. canvas.focus_set()
  24.  
  25. btnRefresh = Button(root,command = refresh, text='Refresh')
  26. canvas.create_window(200, 300, width=100,height=28,anchor=NW, window=btnRefresh)
  27.  
  28. refresh()
  29.  
  30. root.mainloop()
Add Comment
Please, Sign In to add comment