Python 3.x 如何使用Tkinter模拟此表?

Python 3.x 如何使用Tkinter模拟此表?,python-3.x,tkinter,Python 3.x,Tkinter,如何开始使用Tkinter创建类似的表?您必须创建一个ext条目数组,然后在父框架中使用“网格”布局管理器进行布局 开发Python类以允许将网格和单元格内容作为单个表进行管理, 实现像\uuuu getindex\uuuu这样的东西来获取单元格内容,甚至一些反应式编程,允许某些列随着其他地方的值变化而变化,这将是这样一个项目中有趣的部分 要创建网格,只需执行以下操作: import tkinter window = tkinter.Tk() frame = Tkinter.Frame(wind


如何开始使用Tkinter创建类似的表?

您必须创建一个ext条目数组,然后在父框架中使用“网格”布局管理器进行布局

开发Python类以允许将网格和单元格内容作为单个表进行管理, 实现像
\uuuu getindex\uuuu
这样的东西来获取单元格内容,甚至一些反应式编程,允许某些列随着其他地方的值变化而变化,这将是这样一个项目中有趣的部分

要创建网格,只需执行以下操作:

import tkinter
window = tkinter.Tk()
frame = Tkinter.Frame(window)
frame.pack()

entries = {} # this 'entries'is what you might want to specify a custom class to manage
             # for now,a dictionary will do

for j in range(10):
    for i in range(10):
        e = tkinter.Entry(f)
        e.grid(column=i,row=j, borderwidth=0)
        es[i,j] = e
您就在这里。

使用Ttk/Tkinter小部件。这提供了树样式布局或具有标题布局的列表视图样式列

由于
Treeview
小部件来自Tk的主题图标集,因此它在Windows上看起来很合适-选择当前的边框和列标题样式,以便外观与当前发布的示例相匹配

示例(在Python2和Python3中都适用):

这将在Windows上产生类似的结果:


可能的重复是否可以设置第0列的宽度?是。与其他列一样,
条目中的
f
是什么?和es==条目??
try:
    from Tkinter import *
    from ttk import *
except ImportError:  # Python 3
    from tkinter import *
    from tkinter.ttk import *


class App(Frame):

    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.CreateUI()
        self.LoadTable()
        self.grid(sticky = (N,S,W,E))
        parent.grid_rowconfigure(0, weight = 1)
        parent.grid_columnconfigure(0, weight = 1)

    def CreateUI(self):
        tv = Treeview(self)
        tv['columns'] = ('starttime', 'endtime', 'status')
        tv.heading("#0", text='Sources', anchor='w')
        tv.column("#0", anchor="w")
        tv.heading('starttime', text='Start Time')
        tv.column('starttime', anchor='center', width=100)
        tv.heading('endtime', text='End Time')
        tv.column('endtime', anchor='center', width=100)
        tv.heading('status', text='Status')
        tv.column('status', anchor='center', width=100)
        tv.grid(sticky = (N,S,W,E))
        self.treeview = tv
        self.grid_rowconfigure(0, weight = 1)
        self.grid_columnconfigure(0, weight = 1)

    def LoadTable(self):
        self.treeview.insert('', 'end', text="First", values=('10:00',
                             '10:10', 'Ok'))

def main():
    root = Tk()
    App(root)
    root.mainloop()

if __name__ == '__main__':
    main()