import tkinter
from tkinter import *
from tkinter.ttk import *


class FrameTabsBatchTask(Frame):
    def __init__(self, parent):
        super().__init__(parent)
        self.__frame()
        self.tk_table_batch_task_list = self.__tk_table_batch_task_list(self)
        self.tk_button_create = self.__tk_button_create(self)

    def __frame(self):
        self.place(x=0, y=0, width=675, height=510)

    def __tk_table_batch_task_list(self, parent):
        # 表头字段 表头宽度
        columns = {"创建时间": 121, "状态": 121, "进度": 121, "失败": 121, "内容": 121}
        # 初始化表格 表格是基于Treeview，tkinter本身没有表格。show="headings" 为隐藏首列。
        tk_table = Treeview(parent, show="headings", columns=list(columns))
        for text, width in columns.items():  # 批量设置列属性
            tk_table.heading(text, text=text, anchor='center')
            tk_table.column(text, anchor='center', width=width, stretch=False)  # stretch 不自动拉伸

        # 插入数据示例
        # data = [
        #     [1, "github", "https://github.com/iamxcd/tkinter-helper"],
        #     [2, "演示地址", "https://www.pytk.net/tkinter-helper"]
        # ]
        #
        # # 导入初始数据
        # for values in data:
        #     tk_table.insert('', END, values=values)

        tk_table.place(x=30, y=50, width=608, height=420)
        return tk_table

    def __tk_button_create(self, parent):
        btn = Button(parent, text="新建任务", takefocus=False, state=tkinter.DISABLED)
        btn.place(x=560, y=10, width=80, height=30)
        return btn
