from tkinter import *
from tkinter.ttk import *


class WinGUIBatchTaskDetail(Tk):
    def __init__(self):
        super().__init__()
        self.__win()
        self.tk_label_frame_content = Frame_content(self)
        self.tk_label_frame_contact = Frame_contact(self)

    def __win(self):
        self.title("新建群发任务")
        # 设置窗口大小、居中
        width = 600
        height = 600
        screenwidth = self.winfo_screenwidth()
        screenheight = self.winfo_screenheight()
        geometry = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
        self.geometry(geometry)
        self.resizable(width=False, height=False)

class Frame_content(LabelFrame):
    def __init__(self, parent):
        super().__init__(parent)
        self.__frame()
        self.tk_text_content = self.__tk_text_content()

    def __frame(self):
        self.configure(text="发送内容")
        self.place(x=20, y=10, width=560, height=130)

    def __tk_text_content(self):
        text = Text(self)
        text.place(x=5, y=5, width=550, height=100)
        return text


class Frame_contact(LabelFrame):
    def __init__(self, parent):
        super().__init__(parent)
        self.__frame()
        self.tk_table_contact_list = self.__tk_table_contact_list()

    def __frame(self):
        self.configure(text="接收对象")
        self.place(x=20, y=150, width=560, height=400)

    def __tk_table_contact_list(self):
        # 表头字段 表头宽度
        columns = {"微信 ID": 112, "类型": 112, "昵称": 112, "发送时间": 112, "发送状态": 112}
        # 初始化表格 表格是基于Treeview，tkinter本身没有表格。show="headings" 为隐藏首列。
        tk_table = Treeview(self, 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=5, y=5, width=550, height=370)
        return tk_table
