online_search.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import tkinter as tk
  2. from tkinter import ttk
  3. from utils.config import config
  4. class OnlineSearchUI:
  5. def init_ui(self, root):
  6. """
  7. Init online search UI
  8. """
  9. frame_online_search_open_online_search = tk.Frame(root)
  10. frame_online_search_open_online_search.pack(fill=tk.X)
  11. self.open_online_search_label = tk.Label(
  12. frame_online_search_open_online_search, text="开启关键字搜索:", width=13
  13. )
  14. self.open_online_search_label.pack(side=tk.LEFT, padx=4, pady=8)
  15. self.open_online_search_var = tk.BooleanVar(value=config.open_online_search)
  16. self.open_online_search_checkbutton = ttk.Checkbutton(
  17. frame_online_search_open_online_search,
  18. variable=self.open_online_search_var,
  19. onvalue=True,
  20. offvalue=False,
  21. command=self.update_open_online_search,
  22. )
  23. self.open_online_search_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
  24. frame_online_search_page_num = tk.Frame(root)
  25. frame_online_search_page_num.pack(fill=tk.X)
  26. self.page_num_label = tk.Label(
  27. frame_online_search_page_num, text="获取页数:", width=13
  28. )
  29. self.page_num_label.pack(side=tk.LEFT, padx=4, pady=8)
  30. self.page_num_entry = tk.Entry(frame_online_search_page_num)
  31. self.page_num_entry.pack(side=tk.LEFT, padx=4, pady=8)
  32. self.page_num_entry.insert(0, config.online_search_page_num)
  33. self.page_num_entry.bind("<KeyRelease>", self.update_page_num)
  34. frame_online_search_recent_days = tk.Frame(root)
  35. frame_online_search_recent_days.pack(fill=tk.X)
  36. self.recent_days_label = tk.Label(
  37. frame_online_search_recent_days, text="获取时间范围(天):", width=13
  38. )
  39. self.recent_days_label.pack(side=tk.LEFT, padx=4, pady=8)
  40. self.recent_days_entry = tk.Entry(frame_online_search_recent_days)
  41. self.recent_days_entry.pack(side=tk.LEFT, padx=4, pady=8)
  42. self.recent_days_entry.insert(30, config.recent_days)
  43. self.recent_days_entry.bind("<KeyRelease>", self.update_recent_days)
  44. def update_open_online_search(self):
  45. config.set(
  46. "Settings", "open_online_search", str(self.open_online_search_var.get())
  47. )
  48. def update_page_num(self, event):
  49. config.set("Settings", "online_search_page_num", self.page_num_entry.get())
  50. def update_recent_days(self, event):
  51. config.set("Settings", "recent_days", self.recent_days_entry.get())
  52. def change_entry_state(self, state):
  53. for entry in [
  54. "open_online_search_checkbutton",
  55. "page_num_entry",
  56. "recent_days_entry",
  57. ]:
  58. getattr(self, entry).config(state=state)