【发布时间】:2020-12-05 11:53:17
【问题描述】:
我想将 scrapy 与我用 tkinter 制作的 GUI 一起使用,spider 可以单独使用 GUI 正常工作,但是当我使用 GUI 按钮启动 scrapy spider 时,GUI 没有响应,如您在图像中看到的那样.
这是我的代码:
from tkinter import *
import subprocess
class Test():
def __init__(self):
self.root = Tk()
self.root.geometry('300x200')
self.button = Button(self.root,
text = 'Click Me',
command=lambda:self.pop_up())
self.button.pack()
self.root.mainloop()
def scrape(self):
process = subprocess.Popen("scrapy runspider url_scraper.py -o output.csv")
process.wait()
def pop_up(self):
top = Toplevel()
btn = Button(top, text="Output filename: ")
e = Entry(top)
scrape = Button(top, text="Start", command=lambda: [top.destroy(), self.scrape()])
btn.grid(row=0, column=0)
e.grid(row=1, column=1)
scrape.grid(row=2, column=0)
app = Test()
我只是希望它们在我的刮板刮取数据时不要挂起。请帮我解决这个问题。
提前致谢。
【问题讨论】:
-
process.wait()将阻止应用程序。 -
使用线程模块
标签: python-3.x user-interface tkinter web-scraping scrapy