diff --git a/TR/TrialRecommend/Main.py b/TR/TrialRecommend/Main.py index a09850c..d487d12 100644 --- a/TR/TrialRecommend/Main.py +++ b/TR/TrialRecommend/Main.py @@ -101,6 +101,7 @@ class Mainpage: self.init_main_Page() self.update_max() self.image_url(self.current_data_index, self.current_data_image_index) + def to_like_page(self): self.page.destroy() self.init_like_page() @@ -149,6 +150,7 @@ class Mainpage: self.lable_like = tk.Label(self.page2, text='转发人数:', font=('SimHei',15,'bold')) self.lable_like.place(relx=0.29, rely=0.93) + def notes_request(self,next_back): if next_back == 'next': if self.current_data_index + 1 <= self.max_data_count: @@ -233,6 +235,7 @@ class Mainpage: self.init_text() self.init_main_Page() self.image_show() + # 返回上一篇 def back_data(self): if self.max_data_count != 0: @@ -240,6 +243,7 @@ class Mainpage: self.notes_request('back') else: messagebox.showinfo(message='请先搜索') + # 下一篇 def next_data(self): if self.max_data_count != 0: @@ -247,6 +251,7 @@ class Mainpage: self.notes_request('next') else: messagebox.showinfo(message='请先搜索') + # 下一张图片 def next_image(self): @@ -257,6 +262,7 @@ class Mainpage: else: self.current_data_image_index += 1 self.image_url(self.current_data_index, self.current_data_image_index) + # 上一张图片 def pre_image(self): if self.max_iamge_count == 0: @@ -266,6 +272,7 @@ class Mainpage: else: self.current_data_image_index -= 1 self.image_url(self.current_data_image_index) + def researchPage(self): self.clear_csv_file() rs=self.research.get() @@ -278,6 +285,7 @@ class Mainpage: self.init_notes_request() else: messagebox.showinfo(message='网络请求失败,请稍后尝试!') + def init_notes_request(self): with open('data.csv', 'r', encoding='utf-8') as f: reader = csv.reader(f) @@ -288,6 +296,7 @@ class Mainpage: self.init_text() self.init_main_Page() self.image_show() + def image_url(self,col): with open(self.data_csv_file_path,'r',encoding='utf-8') as f: reader = csv.reader(f) @@ -298,6 +307,7 @@ class Mainpage: row=rows i += 1 self.load_image_from_url(self.page,eval(row[3])[col]) + def load_image_from_url(self,View,url): # 使用requests从URL下载图片 response = requests.get(url) @@ -310,11 +320,13 @@ class Mainpage: label = tk.Label(View, image=tk_img) label.image = tk_img # 保持对tk_img的引用,防止被垃圾回收 label.place(relx=0.05, rely=0.07) + def image_show(self): if self.csv_is_empty(): messagebox.showinfo('提示',message='数据加载失败') else: self.image_url(self.current_data_index,0) + def csv_is_empty(self): with open('notes.csv','r',encoding='utf-8') as f2: rows = [] @@ -328,6 +340,7 @@ class Mainpage: if len(rows) == 0: print('notes 无数据') return True + def init_text(self): with open(self.notes_csv_file_path,'r',encoding='utf-8') as f: reader = csv.reader(f) @@ -342,6 +355,7 @@ class Mainpage: self.likes = row[4] self.share = row[5] index += 1 + def update_max(self): with open(self.data_csv_file_path,'r',encoding='utf-8') as f: reader = csv.reader(f) @@ -365,14 +379,17 @@ class Mainpage: for i in reader: counts+=1 self.max_notes_count=counts + def clear_csv_file(self): with open(self.data_csv_file_path, 'w') as file1: # 使用'w'模式打开文件 pass # 不需要执行任何操作,因为打开文件时内容已被清空 with open(self.notes_csv_file_path, 'w') as file2: pass # 不需要执行任何操作,因为打开文件时内容已被清空 + def exit(self): messagebox.showinfo(title='提示', message='欢迎下次使用!') self.root.quit() + def center_window(self, root, width=1300, height=700): # 获取屏幕宽度和高度 screen_width = root.winfo_screenwidth() @@ -394,6 +411,7 @@ class Mainpage: def func_discollect(self): dis_collect.dis_collec(self.user,self.current_data_index) + if __name__ == '__main__': root = tk.Tk() Mainpage(master=root,name='Null') diff --git a/TR/TrialRecommend/dis_collect.py b/TR/TrialRecommend/dis_collect.py index 8ff4140..f3eb818 100644 --- a/TR/TrialRecommend/dis_collect.py +++ b/TR/TrialRecommend/dis_collect.py @@ -4,7 +4,7 @@ from tkinter import messagebox def dis_collec(user,data_index): id='' - with open('TrialRecommend/data.csv', 'r', encoding='utf-8', newline='') as file: + with open('data.csv', 'r', encoding='utf-8', newline='') as file: reader = csv.reader(file) index=0 for row in reader: