ui.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import tkinter
  2. from tkinter import *
  3. from tkinter.ttk import *
  4. from .batch_task.frame_tab import FrameTabsBatchTask
  5. from .start.frame_tab import FrameTabsStart
  6. from .sop.frame_tabs import FrameTabsSop
  7. class WinGUI(Tk):
  8. def __init__(self):
  9. super().__init__()
  10. self.__win()
  11. self.tk_tabs_main_tabs = Frame_main_tabs(self)
  12. def __win(self):
  13. self.title("轻马私域微信机器人助手")
  14. # 设置窗口大小、居中
  15. width = 675
  16. height = 510
  17. screenwidth = self.winfo_screenwidth()
  18. screenheight = self.winfo_screenheight()
  19. geometry = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
  20. self.geometry(geometry)
  21. self.resizable(width=False, height=False)
  22. def scrollbar_autohide(self, vbar, hbar, widget):
  23. """自动隐藏滚动条"""
  24. def show():
  25. if vbar: vbar.lift(widget)
  26. if hbar: hbar.lift(widget)
  27. def hide():
  28. if vbar: vbar.lower(widget)
  29. if hbar: hbar.lower(widget)
  30. hide()
  31. widget.bind("<Enter>", lambda e: show())
  32. if vbar: vbar.bind("<Enter>", lambda e: show())
  33. if vbar: vbar.bind("<Leave>", lambda e: hide())
  34. if hbar: hbar.bind("<Enter>", lambda e: show())
  35. if hbar: hbar.bind("<Leave>", lambda e: hide())
  36. widget.bind("<Leave>", lambda e: hide())
  37. def v_scrollbar(self, vbar, widget, x, y, w, h, pw, ph):
  38. widget.configure(yscrollcommand=vbar.set)
  39. vbar.config(command=widget.yview)
  40. vbar.place(relx=(w + x) / pw, rely=y / ph, relheight=h / ph, anchor='ne')
  41. def h_scrollbar(self, hbar, widget, x, y, w, h, pw, ph):
  42. widget.configure(xscrollcommand=hbar.set)
  43. hbar.config(command=widget.xview)
  44. hbar.place(relx=x / pw, rely=(y + h) / ph, relwidth=w / pw, anchor='sw')
  45. def create_bar(self, master, widget, is_vbar, is_hbar, x, y, w, h, pw, ph):
  46. vbar, hbar = None, None
  47. if is_vbar:
  48. vbar = Scrollbar(master)
  49. self.v_scrollbar(vbar, widget, x, y, w, h, pw, ph)
  50. if is_hbar:
  51. hbar = Scrollbar(master, orient="horizontal")
  52. self.h_scrollbar(hbar, widget, x, y, w, h, pw, ph)
  53. self.scrollbar_autohide(vbar, hbar, widget)
  54. class Frame_main_tabs(Notebook):
  55. def __init__(self, parent):
  56. super().__init__(parent)
  57. self.__frame()
  58. def __frame(self):
  59. self.tk_tabs_start = FrameTabsStart(self)
  60. self.add(self.tk_tabs_start, text="启动服务")
  61. self.tk_tabs_batch_task = FrameTabsBatchTask(self)
  62. self.add(self.tk_tabs_batch_task, text="群发管理")
  63. self.tk_tabs_sop = FrameTabsSop(self)
  64. self.add(self.tk_tabs_sop, text="SOP管理")
  65. self.place(x=0, y=0, width=675, height=510)