Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My current goal is to display data onto a message box. As this picture shows, the data is all over the place, but if I send it to Excel it looks perfectly fine whereas the message box is just not even.

How can I even out the displayed data on messagebox just to look like the excel?

Here is my code:

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
selling','spot
buying','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() 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
227 views
Welcome To Ask or Share your Answers For Others

1 Answer

I have good experience using pandas with tabulate and then inserting in Tkinter window with tkinterhtml.

You have "stralign" and "numalign" in tabulate and even "floatfmt" for all sorts of formats and alignment while creating tables.

example for usage:

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...