about.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import tkinter as tk
  2. from PIL import Image, ImageTk
  3. import webbrowser
  4. from utils.config import resource_path
  5. class AboutUI:
  6. def init_ui(self, root=None, version=None):
  7. about_window = tk.Toplevel(root)
  8. about_window.title("关于")
  9. about_window_width = 430
  10. about_window_height = 480
  11. version_frame = tk.Frame(about_window)
  12. version_frame.pack(side=tk.TOP, fill=tk.X)
  13. version_label = tk.Label(version_frame, text=f"版本: {version}")
  14. version_label.pack()
  15. author_row = tk.Frame(about_window)
  16. author_row.pack()
  17. author_row_column1 = tk.Frame(author_row)
  18. author_row_column1.pack(side=tk.LEFT, fill=tk.Y)
  19. author_row_column2 = tk.Frame(author_row)
  20. author_row_column2.pack(side=tk.RIGHT, fill=tk.Y)
  21. author_label = tk.Label(author_row_column1, text="作者:")
  22. author_label.pack()
  23. author_name = tk.Label(
  24. author_row_column2, text="Govin", fg="blue", cursor="hand2"
  25. )
  26. author_name.pack()
  27. author_name.bind(
  28. "<Button-1>",
  29. lambda e: webbrowser.open_new_tab("https://github.com/Guovin"),
  30. )
  31. project_row = tk.Frame(about_window)
  32. project_row.pack()
  33. project_row_column1 = tk.Frame(project_row)
  34. project_row_column1.pack(side=tk.LEFT, fill=tk.Y)
  35. project_row_column2 = tk.Frame(project_row)
  36. project_row_column2.pack(side=tk.RIGHT, fill=tk.Y)
  37. project_label = tk.Label(project_row_column1, text="项目地址:")
  38. project_label.pack()
  39. project_link = tk.Label(
  40. project_row_column2,
  41. text="https://github.com/Guovin/TV",
  42. fg="blue",
  43. cursor="hand2",
  44. )
  45. project_link.pack()
  46. project_link.bind(
  47. "<Button-1>",
  48. lambda e: webbrowser.open_new_tab("https://github.com/Guovin/TV"),
  49. )
  50. disclaimer_label = tk.Label(
  51. version_frame,
  52. text="本软件仅供学习交流用途,数据均来源于互联网,禁止商业行为,一切法律责任与作者无关。",
  53. wraplength=265,
  54. )
  55. disclaimer_label.pack()
  56. image = Image.open(resource_path("static/images/alipay.jpg"))
  57. resized_image = image.resize((250, 300))
  58. photo = ImageTk.PhotoImage(resized_image)
  59. image_label = tk.Label(about_window, image=photo)
  60. image_label.image = photo
  61. image_label.pack()
  62. appreciate_label = tk.Label(about_window, text="请我喝杯咖啡☕️吧~")
  63. appreciate_label.pack()
  64. confirm_button = tk.ttk.Button(
  65. about_window, text="确定", command=about_window.destroy
  66. )
  67. confirm_button.pack(side=tk.RIGHT, padx=5)
  68. main_width = root.winfo_width()
  69. main_height = root.winfo_height()
  70. main_x = root.winfo_x()
  71. main_y = root.winfo_y()
  72. pos_x = main_x + (main_width // 2) - (about_window_width // 2)
  73. pos_y = main_y + (main_height // 2) - (about_window_height // 2)
  74. about_window.geometry(
  75. f"{about_window_width}x{about_window_height}+{pos_x}+{pos_y}"
  76. )
  77. about_window.iconbitmap(resource_path("static/images/favicon.ico"))