ui.py 2.6 KB

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