forked from wate123/PandaTV_Subscriber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_display.py
94 lines (71 loc) · 3.31 KB
/
main_display.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from tkinter import *
from crawl import Crawl
import threading
import time
class MainDisplay:
def __init__(self,goal,time):
'''goal = 今日订阅目标(增加量
time = 刷新时间 (分钟)'''
self.goal = goal
self.time_in_seconds = time*60
self.c = Crawl(goal) # 初始化Crawler
# 设置GUI界面
self.root = Tk()
########################### 设置初始windows位置 ##################
self.root.geometry('220x45+40+560') # 长 X 宽 + 向右平移 + 向下平移
#####################################################################
self.root.title('就是要莽')
top_frame = Frame(self.root) # 上层frame用于显示信息
top_frame.pack(fill=BOTH)
self.label_text1 = StringVar()
self.label_text1.set('今日订阅:')
text_label = Label(top_frame, textvariable=self.label_text1,font="32")
text_label.grid(row=0,sticky='w')
self.cur_num = StringVar() # 当前订阅数
num_label = Label(top_frame, textvariable=self.cur_num,fg="red",font="28")
num_label.grid(row=0, column=1,sticky='e')
self.label_text2 = StringVar()
self.label_text2.set('/'+str(self.goal))
objective_label = Label(top_frame,textvariable=self.label_text2,font="28")
objective_label.grid(row=0,column=2,sticky='w')
top_frame.columnconfigure(0,weight=4) # 调整widget位置
top_frame.columnconfigure(1,weight=2)
top_frame.columnconfigure(2,weight=2)
bottom_frame = Frame(self.root) # 下层frame用于手动获取最新订阅量
bottom_frame.pack(fill=BOTH, side=BOTTOM)
refresh_button = Button(bottom_frame, text='手动刷新',font="25")
refresh_button.bind('<Button-1>', self.refresh)
refresh_button.grid(row=0,column=0,sticky=("N", "S", "E", "W"))
fans_button=Button(bottom_frame,text='当前订阅',font="25")
fans_button.bind('<Button-1>', self.refresh_total_fans)
fans_button.grid(row=0,column=1,sticky=("N", "S", "E", "W"))
bottom_frame.columnconfigure(0,weight=1)
bottom_frame.columnconfigure(1,weight=1)
self.root.rowconfigure(0,weight=3) # 调整widget位置
self.root.rowconfigure(1,weight=1)
t = threading.Thread(target=self.start_crawl) # 开始运行
t.daemon = True
t.start()
self.root.mainloop()
def print_fans(self):
self.cur_num.set(self.c.get_incresed_fans())
self.label_text1.set('今日订阅:')
self.label_text2.set('/'+str(self.goal))
def refresh(self,event):
t = threading.Thread(target=self.print_fans)
t.daemon = True
t.start()
def start_crawl(self):
while True:
self.cur_num.set(self.c.get_incresed_fans())
time.sleep(self.time_in_seconds)
def print_total_fans(self):
self.cur_num.set(self.c.get_fans_str())
self.label_text1.set('总订阅:')
self.label_text2.set('')
time.sleep(3)
self.print_fans()
def refresh_total_fans(self,event):
t = threading.Thread(target=self.print_total_fans)
t.daemon = True
t.start()