如何在消息框中有序地整理数据? python-tkinter

问题描述 投票:0回答:1

从网站上抓取数据并将其放在消息框中。message box但它不能像Excel一样井然有序。Excel

我尝试了很多方法,但是失败了。...

import tkinter as tk
import tkinter.messagebox as tm
import pandas
import datetime


def currency_rate():
    dfs=pandas.read_html('https://rate.bot.com.tw/xrt?Lang=en-US')
    currency=dfs[1] 
    currency= currency.iloc[:,0:5] 
    currency.columns=['currency','cash-buying','cash-selling','spot-buying','spot-selliing'] 
    currency['currency'] =currency['currency'].str.extract('\((\w+)\)')  
    date=datetime.datetime.now() 
    result_date="Update: Date {:4}.{:02}.{:02}-Time {:02}:{:02}:{:02}".format(date.year,date.month,date.day,date.hour,date.minute,date.second)
    tm.showinfo(title =str(result_date), message =str(currency))  

def currency_rate_import():    
    dfs=pandas.read_html('https://rate.bot.com.tw/xrt?Lang=en-US')
    currency=dfs[1] 
    currency= currency.iloc[:,0:5] 
    currency.columns=['currency','cash-buying','cash\nselling','spot\nbuying','spot-selliing'] 
    currency['currency'] =currency['currency'].str.extract('\((\w+)\)')  
    date=datetime.datetime.now() 
    currency.to_excel('Currency Rate{:4}{:02}{:02}-Daily.xlsx'.format(date.year,date.month,date.day))

my_window=tk.Tk()


btn2=tk.Button(my_window,text="Export (Excel)",font="Calibri 14",width=25,height=1,command=currency_rate_import)
btn2.pack(side=tk.BOTTOM) 
btn1=tk.Button(my_window,text="Today\'s exchange rate",font="Calibri 14",background="yellow",width=25,height=1,command=currency_rate)
btn1.pack(side=tk.BOTTOM) 

my_window.mainloop() 
python tkinter messagebox
1个回答
0
投票

我在tabulate中使用熊猫,然后在tkinterhtml中插入Tkinter窗口中有很好的经验。

在创建表时,表中甚至所有类型的格式和对齐方式都具有制表符“ stralign”和“ numalign”,甚至“ floatfmt”。

用法示例:

from tabulate import tabulate
from tkinterhtml import HtmlFrame

html = tabulate(df, 
                headers='keys',
                floatfmt=",.1f", tablefmt='html',
                numalign='center', stralign='center')
top = tk.Toplevel()
hf = HtmlFrame(top)
hf.pack()
hf.set_content(html)
© www.soinside.com 2019 - 2024. All rights reserved.