Creating a table like structure in python

孤街醉人 提交于 2019-12-11 21:10:59

问题


I am making a download manager in python.. I want to create a table like structure with multiple columns and rows to show:

Download name, download status (paused/downloading), download size and other information interactively.

Can anyone give me ideas on how to create a table-like structure where I can easily add the data mentioned above?


回答1:


The ttk treeview widget allows you to have multiple columns. For example:

import Tkinter as tk # python 2.7
import ttk
...
root = tk.Tk()
...
tree = ttk.Treeview(root, ...)  
tree.configure(columns=('size', 'modified', 'owner'))
...
tree.insert('', 'end', text='item 1', values=('20k','yesterday', 'kilgore trout'))

For more information see http://www.tkdocs.com/tutorial/tree.html




回答2:


Your question is a bit confusing - you're talking about data structure and persistence then about list box (GUI stuff...)

wrt/ the data structure and persistence part a "table like" structure with "rows and columns" is easily modeled as a list of ducts or list of tuples. For the perstitance part you can serialize your list as json and write it to a file or write it as CSV ( using the stdlib CVS package) or use a SQL db.



来源:https://stackoverflow.com/questions/16052969/creating-a-table-like-structure-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!