【发布时间】:2021-07-22 23:20:57
【问题描述】:
这是一个图形窗口,可以抓取并显示图标之间的任何错误。有两个从其他 py 文件中调用的抓取脚本(msg1 和 msg2),更准确地说,它们的抓取功能(Selenium)被调用。抓取正确完成,
我想在文本框中查看抓取,所以我想在文本框中查看 python 控制台中发生的情况。我想在文本框中显示的是 msg1 和 msg2 (这将是两个抓取 py 文件)。我补充说,我想在抓取期间(实时)显示抓取,而不是在函数结束时显示:在函数运行时
如何在文本框中查看 msg1 和 msg2?
from tkinter import *
from tkinter import ttk
import tkinter as tk
from File import Scraping_Nome_Campionati
from File import Scraping_Nome_Squadre_MIO
from File.Scraping_Nome_Campionati import scraping_nome_campionati_e_tor
from File.Scraping_Nome_Squadre_MIO import scraping_nome_squadre_e_tor
def draw_graph():
test_scraping=tk.Toplevel()
test_scraping.title("aaaa")
test_scraping.geometry("1100x900")
test_scraping.configure(bg='#282828')
def do_scraping():
#Start the scraping functions of the two py files and search for errors
#msg1 and msg2 recall the two scraping py files, because they check for scraping errors by showing the green icon and the red icon
msg1 = Scraping_Nome_Campionati.scraping_nome_campionati_e_tor()
if msg1:
message1.configure(text=msg1)
message1.configure(foreground="red")
vuoto_elenco_campionati.config(image=render7)
else:
vuoto_elenco_campionati.config(image=render8)
message1.configure(foreground="green")
msg2 = Scraping_Nome_Squadre_MIO.scraping_nome_squadre_e_tor()
if msg2:
message2.configure(text=msg2)
message2.configure(foreground="red")
vuoto_elenco_squadre.config(image=render7)
else:
vuoto_elenco_squadre.config(image=render8)
message2.configure(foreground="green")
text = tk.Text(test_scraping,width=80,height=50, background="black", foreground="white")
text.pack()
text.place(x=450, y=20)
button = Button(test_scraping, text="Avvia", bg='#e95420', foreground='white', command=do_scraping)
button.place(x=116, y=512)
【问题讨论】:
-
放入一个线程并使用队列与主线程通信(也可以使用多处理)然后有一种更新功能(使用
.after()方法)从队列中获取数据并插入它在小部件中 -
@matiiss 你能用代码告诉我答案吗?我不太明白。谢谢和抱歉。
标签: python python-3.x selenium-webdriver tkinter