如何在python rss框架中添加内容 初学
import tkinter import urllib import xml.parsers.expat class MyXML: def __init__(self, edit): self.parser = xml.parsers.expat.ParserCreate() self.parser.StartElementHandler = self.start self.parser.EndElementHandler = self.end self.parser.CharacterDataHandler = self.data self.title = False self.description = False self.date = False self.edit = edit def start(self, name, attrs): if name == 'title': self.title = True elif name == 'description': self.description = True elif name == 'pubDate': self.date = True else: pass def end(self, name): if name == 'title': self.title = False elif name == 'description': self.description = False elif name == 'pubDate': self.date = False else: pass def data(self,data): if self.title: self.edit.insert(tkinter.END, '******************************\n') self.edit.insert(tkinter.END, 'Title: ') self.edit.insert(tkinter.END, data + '\n') elif self.description: self.edit.insert(tkinter.END, 'Date: ') self.edit.insert(tkinter.END, data + '\n') elif self.date: self.edit.insert(tkinter.END, 'Date: ') self.edit.insert(tkinter.END, data + '\n') else: pass def feed(self, data): self.parser.Parse(data, 0) class Window: def __init__(self, root): self.root = root self.entryUrl = tkinter.Entry(root,width = 30) self.entryUrl.place(x = 65, y = 15) self.get = tkinter.Button(root, text = '读取RSS', command = self.Get, font = ('system','10')) self.get.place(x = 350, y = 15) self.frame = tkinter.Frame(root, bd=2) self.scrollbar = tkinter.Scrollbar(self.frame) self.edit = tkinter.Text(self.frame,yscrollcommand = self.scrollbar.set, width = 96, height = 32) self.scrollbar.config(command=self.edit.yview) self.edit.pack(side = tkinter.LEFT) self.scrollbar.pack(side=tkinter.RIGHT, fill=tkinter.Y) self.frame.place(y = 50) def Get(self): url = self.entryUrl.get() page = urllib.urlopen(url) data = page.read() parser = MyXML(self.edit) parser.feed(data) page.close() root = tkinter.Tk() root.title('RSS 阅读器') root.minsize(700,500) root.maxsize(700,500) root.mainloop()
粘贴自互联网,这个做出来只有一个GUI视图,如何在里面添加东西
傲娇的双马尾
10 years, 8 months ago