today study_2005.1.27

博客围绕 GC Class 展开,介绍其可控制自动回收未使用内存的系统垃圾回收器。该类的方法影响对象垃圾回收及资源释放时间,属性提供系统可用内存总量和对象内存周期类别信息。还说明了垃圾回收器工作方式及自动或强制回收的条件。

 

 

GC Class 坚忍不拔必定成功

Controls the system garbage collector, a service that automatically reclaims unused memory.

The methods in this class influence when an object is garbage collected and when resources allocated by an object are released. Properties in this class provide information about the total amount of memory available in the system and the age category, or generation, of memory allocated to an object.

此类中的方法影响何时对对象进行垃圾回收以及何时释放对象所分配的资源。此类中的属性提供以下信息:系统可用内存总量、分配给对象的内存的周期类别(代)。

 

influence  n. 1.影响,感化 2.权势,势力vt. 影响,感化,左右

age category 周期类别

The garbage collector tracks and reclaims objects allocated in managed memory. Periodically, the garbage collector performs garbage collection to reclaim memory allocated to objects for which there are no valid references. Garbage collection happens automatically when a request for memory cannot be satisfied using available free memory. Alternatively, an application can force garbage collection using the Collect method.

垃圾回收器跟踪回收托管内存中分配的对象。垃圾回收器定期执行垃圾回收以回收分配给没有有效引用的对象的内存。当使用可用内存不能满足内存请求时,垃圾回收会自动进行。或者,应用程序可以使用 Collect 方法强制进行垃圾回收。

Alternatively ad. 二者择一地,做为选择

Periodically ad. 周期性地,定时性地

Exclusively  ad. 排外地,独有地,专门地

explicitly adv.清晰地

 

 

 

请先记住这段代码:import tkinter as tk from tkinter import messagebox import time from datetime import date class StudyRecorder: def __init__(self, root): self.root = root self.root.title("学习记录") self.root.geometry("300x300") self.start_time = None self.total_study_time = 0 self.today_study_time = 0 self.today = date.today() self.study_records = [] self.label = tk.Label(root, text="学习记录", font=("Arial", 20)) self.label.pack(pady=10) self.time_label = tk.Label(root, text="0:00", font=("Arial", 24)) self.time_label.pack(pady=10) self.total_time_label = tk.Label(root, text="总学习时长: 0:00", font=("Arial", 14)) self.total_time_label.pack(pady=5) self.today_time_label = tk.Label(root, text="当天学习时长: 0:00", font=("Arial", 14)) self.today_time_label.pack(pady=5) self.start_button = tk.Button(root, text="开始学习", command=self.start_study) self.start_button.pack(pady=5) self.rest_button = tk.Button(root, text="休息一下", command=self.take_rest, state=tk.DISABLED) self.rest_button.pack(pady=5) self.record_button = tk.Button(root, text="学习记录", command=self.show_records) self.record_button.pack(pady=5) self.end_button = tk.Button(root, text="结束学习", command=self.end_study) self.end_button.pack(pady=5) def start_study(self): self.start_time = time.time() self.start_button.config(state=tk.DISABLED) self.rest_button.config(state=tk.NORMAL) self.update_time() def take_rest(self): if self.start_time: end_time = time.time() study_duration = end_time - self.start_time current_date = date.today() if current_date == self.today: self.today_study_time += study_duration else: self.today = current_date self.today_study_time = study_duration self.total_study_time += study_duration self.study_records.append((current_date, study_duration)) self.start_time = None self.start_button.config(state=tk.NORMAL) self.rest_button.config(state=tk.DISABLED) self.time_label.config(text="0:00") self.update_total_time_labels() def show_records(self): record_text = "" for record_date, record in self.study_records: record_text += f"{record_date}: {int(record // 60)} 分 {int(record % 60)} 秒\n" record_text += f"总学习时长: {int(self.total_study_time // 60)} 分 {int(self.total_study_time % 60)} 秒\n" record_text += f"当天学习时长: {int(self.today_study_time // 60)} 分 {int(self.today_study_time % 60)} 秒" messagebox.showinfo("学习记录", record_text) def end_study(self): if self.start_time: self.take_rest() self.root.destroy() def update_time(self): if self.start_time: elapsed_time = time.time() - self.start_time minutes = int(elapsed_time // 60) seconds = int(elapsed_time % 60) time_str = f"{minutes}:{seconds:02d}" self.time_label.config(text=time_str) self.root.after(1000, self.update_time) def update_total_time_labels(self): total_minutes = int(self.total_study_time // 60) total_seconds = int(self.total_study_time % 60) today_minutes = int(self.today_study_time // 60) today_seconds = int(self.today_study_time % 60) self.total_time_label.config(text=f"总学习时长: {total_minutes}:{total_seconds:02d}") self.today_time_label.config(text=f"当天学习时长: {today_minutes}:{today_seconds:02d}") if __name__ == "__main__": root = tk.Tk() app = StudyRecorder(root) root.mainloop()
最新发布
12-03
下面是一个使用 Python 的 `tkinter` 库实现简单学习记录功能的代码示例。该程序允许用户输入学习内容和学习时间,点击保存按钮后将记录保存到一个文本文件中。 ```python import tkinter as tk from tkinter import messagebox def save_record(): content = entry_content.get() time = entry_time.get() if content and time: with open('learning_records.txt', 'a', encoding='utf-8') as file: file.write(f"学习内容: {content}, 学习时间: {time}\n") messagebox.showinfo("提示", "记录保存成功!") entry_content.delete(0, tk.END) entry_time.delete(0, tk.END) else: messagebox.showerror("错误", "请输入学习内容和学习时间!") # 创建主窗口 root = tk.Tk() root.title("学习记录工具") # 创建标签和输入框 label_content = tk.Label(root, text="学习内容:") label_content.pack() entry_content = tk.Entry(root, width=50) entry_content.pack() label_time = tk.Label(root, text="学习时间:") label_time.pack() entry_time = tk.Entry(root, width=50) entry_time.pack() # 创建保存按钮 button_save = tk.Button(root, text="保存记录", command=save_record) button_save.pack() # 运行主循环 root.mainloop() ``` ### 代码说明 1. **导入库**:导入 `tkinter` 库用于创建 GUI,导入 `messagebox` 用于显示提示信息。 2. **定义保存记录函数**:`save_record` 函数用于获取用户输入的学习内容和学习时间,并将其保存到 `learning_records.txt` 文件中。如果输入为空,则显示错误提示。 3. **创建主窗口**:使用 `tk.Tk()` 创建主窗口,并设置窗口标题。 4. **创建标签和输入框**:使用 `tk.Label` 创建标签,使用 `tk.Entry` 创建输入框,用于用户输入学习内容和学习时间。 5. **创建保存按钮**:使用 `tk.Button` 创建保存按钮,点击按钮时调用 `save_record` 函数。 6. **运行主循环**:使用 `root.mainloop()` 运行主循环,使窗口保持显示状态。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值