如何使消息框上的数据有序? python-tkinter
How do I make data orderly on the message box? python-tkinter
我目前的目标是将数据显示到
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()
我在使用 pandas 和 tabulate and then inserting in Tkinter window with tkinterhtml 时有很好的经验。
您在表格中有 "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)
我目前的目标是将数据显示到 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()
我在使用 pandas 和 tabulate and then inserting in Tkinter window with tkinterhtml 时有很好的经验。
您在表格中有 "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)