from tkinter import * from tkinter.ttk import * class WinGUIBatchTaskCreate(Tk): def __init__(self): super().__init__() self.__win() self.tk_label_frame_content = Frame_content(self) self.tk_label_frame_contact = Frame_contact(self) self.tk_button_send = self.__tk_button_send() 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) def __tk_button_send(self): btn = Button(self, text="发送") btn.place(x=500, y=560, width=80, height=30) return btn 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_label_lab_type = self.__tk_label_lab_type() self.tk_select_box_type = self.__tk_select_box_type() self.tk_label_lab_label = self.__tk_label_lab_label() self.tk_select_box_label = self.__tk_select_box_label() self.tk_table_contact_list = self.__tk_table_contact_list() def __frame(self): self.configure(text="选择联系人或群组(全选:control + A | 多选:control + shift⬆️)") self.place(x=20, y=150, width=560, height=400) def __tk_label_lab_type(self): label = Label(self, text="类型", anchor="center") label.place(x=5, y=5, width=50, height=25) return label def __tk_select_box_type(self): cb = Combobox(self, state="readonly") cb['values'] = ("联系人", "群组") cb.place(x=70, y=5, width=150, height=25) cb.set("联系人") return cb def __tk_label_lab_label(self): label = Label(self, text="标签", anchor="center") label.place(x=240, y=5, width=50, height=25) return label def __tk_select_box_label(self): cb = Combobox(self, state="readonly") cb['values'] = [] cb.place(x=300, y=5, width=150, height=25) return cb def __tk_table_contact_list(self): # 表头字段 表头宽度 columns = {"微信 ID": 110, "类型": 165, "昵称": 275} # 初始化表格 表格是基于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=40, width=550, height=335) return tk_table