ui_batch_task_create.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. from tkinter import *
  2. from tkinter.ttk import *
  3. class WinGUIBatchTaskCreate(Tk):
  4. def __init__(self):
  5. super().__init__()
  6. self.__win()
  7. self.tk_label_frame_content = Frame_content(self)
  8. self.tk_label_frame_contact = Frame_contact(self)
  9. self.tk_button_send = self.__tk_button_send()
  10. def __win(self):
  11. self.title("新建群发任务")
  12. # 设置窗口大小、居中
  13. width = 600
  14. height = 600
  15. screenwidth = self.winfo_screenwidth()
  16. screenheight = self.winfo_screenheight()
  17. geometry = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
  18. self.geometry(geometry)
  19. self.resizable(width=False, height=False)
  20. def __tk_button_send(self):
  21. btn = Button(self, text="发送")
  22. btn.place(x=500, y=560, width=80, height=30)
  23. return btn
  24. class Frame_content(LabelFrame):
  25. def __init__(self, parent):
  26. super().__init__(parent)
  27. self.__frame()
  28. self.tk_text_content = self.__tk_text_content()
  29. def __frame(self):
  30. self.configure(text="发送内容")
  31. self.place(x=20, y=10, width=560, height=130)
  32. def __tk_text_content(self):
  33. text = Text(self)
  34. text.place(x=5, y=5, width=550, height=100)
  35. return text
  36. class Frame_contact(LabelFrame):
  37. def __init__(self, parent):
  38. super().__init__(parent)
  39. self.__frame()
  40. self.tk_label_lab_type = self.__tk_label_lab_type()
  41. self.tk_select_box_type = self.__tk_select_box_type()
  42. self.tk_label_lab_label = self.__tk_label_lab_label()
  43. self.tk_select_box_label = self.__tk_select_box_label()
  44. self.tk_table_contact_list = self.__tk_table_contact_list()
  45. def __frame(self):
  46. self.configure(text="选择联系人或群组(全选:control + A | 多选:control + shift⬆️)")
  47. self.place(x=20, y=150, width=560, height=400)
  48. def __tk_label_lab_type(self):
  49. label = Label(self, text="类型", anchor="center")
  50. label.place(x=5, y=5, width=50, height=25)
  51. return label
  52. def __tk_select_box_type(self):
  53. cb = Combobox(self, state="readonly")
  54. cb['values'] = ("联系人", "群组")
  55. cb.place(x=70, y=5, width=150, height=25)
  56. cb.set("联系人")
  57. return cb
  58. def __tk_label_lab_label(self):
  59. label = Label(self, text="标签", anchor="center")
  60. label.place(x=240, y=5, width=50, height=25)
  61. return label
  62. def __tk_select_box_label(self):
  63. cb = Combobox(self, state="readonly")
  64. cb['values'] = []
  65. cb.place(x=300, y=5, width=150, height=25)
  66. return cb
  67. def __tk_table_contact_list(self):
  68. # 表头字段 表头宽度
  69. columns = {"微信 ID": 110, "类型": 165, "昵称": 275}
  70. # 初始化表格 表格是基于Treeview,tkinter本身没有表格。show="headings" 为隐藏首列。
  71. tk_table = Treeview(self, show="headings", columns=list(columns))
  72. for text, width in columns.items(): # 批量设置列属性
  73. tk_table.heading(text, text=text, anchor='center')
  74. tk_table.column(text, anchor='center', width=width, stretch=False) # stretch 不自动拉伸
  75. # 插入数据示例
  76. # data = [
  77. # [1, "github", "https://github.com/iamxcd/tkinter-helper"],
  78. # [2, "演示地址", "https://www.pytk.net/tkinter-helper"]
  79. # ]
  80. #
  81. # # 导入初始数据
  82. # for values in data:
  83. # tk_table.insert('', END, values=values)
  84. tk_table.place(x=5, y=40, width=550, height=335)
  85. return tk_table