【发布时间】:2020-01-20 08:03:53
【问题描述】:
我想将创建 csv 文件的 Yahoo 收入日历页面 scraper 转换为 GUI,但我注意到如果当天报告的公司太多,tkinter 窗口就这么大显示设定的金额。我想知道是否有办法在我的窗口中实现滚动条。感谢任何帮助!
from tkinter import *
from tkinter.tix import *
import csv
from datetime import date
import yahooFinanceToCSV
root = Tk()
# open file
with open(r'earnings_{}.csv'.format(date.today()), newline = "") as file:
reader = csv.reader(file)
# r and c tell us where to grid the labels
r = 0
for col in reader:
c = 0
for row in col:
# i've added some styling
label = tkinter.Label(root, width = 35, height = 2, \
text = row, relief = tkinter.RIDGE)
label.grid(row = r, column = c)
c += 1
r += 1
root.mainloop()
我的雅虎收入scraper代码
import pandas as pd
from datetime import date
# Forcing Pandas to display max rows and columns.
pd.option_context('display.max_rows', None, 'display.max_columns', None)
# Reading the earnings calendar table on yahoo finance website.
# earnings = pd.read_html('https://finance.yahoo.com/calendar/earnings')[0]
earnings = pd.read_html("https://finance.yahoo.com/calendar/earnings?from=2020-01-19&to=2020-01-25&day=2020-01-21")[0]
# Writing to a CSV file.
earnings.to_csv(r'earnings_{}.csv'.format(date.today()), index=None)
注意:由于有 40 多家公司报告,HTML 被强制发布到 2020 年 1 月 21 日。通常我每天运行代码以获得当天的收入,但 2020 年 1 月 21 日有助于重现需要解决的问题。
【问题讨论】:
标签: python python-3.x tkinter scrollbar