【发布时间】:2021-10-21 20:14:31
【问题描述】:
我使用包pandastable 显示来自pandas 的dataframes。我想根据内容自动调整列的宽度。在pandastable 的文档(https://pandastable.readthedocs.io/en/latest/_modules/pandastable/core.html#Table.setRowColors)中有一个函数adjustColumnWidths。但是,该列仍然太小,尽管窗口中会有空间。我使用下面的代码,Dataframe 只是一个例子:
import tkinter as tk
from pandastable import Table
import pandas as pd
root = tk.Tk()
root.geometry("1500x1000")
frame = tk.Frame(root)
frame.pack(fill="both", expand=True)
df = pd.DataFrame()
df["column1"] = [1,2,32342323424342342324342332442323423234423423234999999]
df["column2"] = ["a","b","c"]
df["column3"] = ["a"*100]*3
pt = Table(frame, dataframe=df, width=300)
pt.adjustColumnWidths(limit=30)
pt.show()
root.mainloop()
【问题讨论】: