吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2106|回复: 45
收起左侧

[Python 原创] 史上最丑的备忘录

  [复制链接]
phantomxjc 发表于 2024-3-25 10:41
新写的一个备忘录,按自己的需求做的有每日必做事情以及日常备忘工作

'''
import tkinter as tk
from tkinter import ttk, messagebox, simpledialog
from PIL import Image, ImageTk
import os

class MemoApp(tk.Tk):
    def __init__(self):
        super().__init__()
        self.title("备忘录")
        self.geometry("400x400")
        self.resizable(False, False)

        # 创建笔记本卡片
        self.notebook = ttk.Notebook(self)
        self.notebook.pack(expand=True, fill="both")

        # 创建每日必做事项卡片
        self.daily_tasks_frame = tk.Frame(self.notebook)
        self.notebook.add(self.daily_tasks_frame, text="每日必做事项")
        self.daily_tasks_list = tk.Listbox(self.daily_tasks_frame)
        self.daily_tasks_list.pack(expand=True, fill="both")
        self.add_daily_task_button = tk.Button(self.daily_tasks_frame, text="添加任务", command=self.add_daily_task)
        self.add_daily_task_button.pack(side="left")
        self.delete_daily_task_button = tk.Button(self.daily_tasks_frame, text="删除任务",
                                                  command=self.delete_daily_task)
        self.delete_daily_task_button.pack(side="right")

        # 创建备忘录卡片
        self.memo_frame = tk.Frame(self.notebook)
        self.notebook.add(self.memo_frame, text="备忘栏")
        self.memo_list = tk.Listbox(self.memo_frame)
        self.memo_list.pack(expand=True, fill="both")
        self.add_memo_button = tk.Button(self.memo_frame, text="添加备忘", command=self.add_memo)
        self.add_memo_button.pack(side="left")
        self.delete_memo_button = tk.Button(self.memo_frame, text="删除备忘", command=self.delete_memo)
        self.delete_memo_button.pack(side="right")
        self.read_txt("每日必做.txt","备忘录.txt")

    def add_daily_task(self):
        task = tk.simpledialog.askstring("添加任务", "请输入每日必做事项:")
        if task:
            self.daily_tasks_list.insert(tk.END, task)
            with open("每日必做.txt", 'w', encoding='utf-8') as file:
                # 遍历Listbox中的所有项
                for item in self.daily_tasks_list.get(0, tk.END):
                    # 将每一项写入文件,并在其后添加一个换行符
                    file.write(item + '\n')

    def delete_daily_task(self):
        selected_index = self.daily_tasks_list.curselection()
        if selected_index:
            self.daily_tasks_list.delete(selected_index[0])
            with open("每日必做.txt", 'w', encoding='utf-8') as file:
                # 遍历Listbox中的所有项
                for item in self.daily_tasks_list.get(0, tk.END):
                    # 将每一项写入文件,并在其后添加一个换行符
                    file.write(item + '\n')

    def add_memo(self):
        memo = tk.simpledialog.askstring("添加备忘", "请输入备忘内容:")
        if memo:
            self.memo_list.insert(tk.END, memo)
            with open("备忘录.txt", 'w', encoding='utf-8') as file:
                # 遍历Listbox中的所有项
                for item in self.memo_list.get(0, tk.END):
                    # 将每一项写入文件,并在其后添加一个换行符
                    file.write(item + '\n')

    def delete_memo(self):
        selected_index = self.memo_list.curselection()
        if selected_index:
            self.memo_list.delete(selected_index[0])
            with open("备忘录.txt", 'w', encoding='utf-8') as file:
                # 遍历Listbox中的所有项
                for item in self.memo_list.get(0, tk.END):
                    # 将每一项写入文件,并在其后添加一个换行符
                    file.write(item + '\n')
    def read_txt(self,file_path1,file_path2):
        try:
            # 读取txt文件内容
            if not os.path.exists(file_path1):
                # 如果文件不存在,则创建它
                with open(file_path1, 'w') as file:
                    file.write('')
            with open(file_path1, "r") as file:  #"E:\每日必做.txt"
                #content = file.read()
                lines = file.readlines()
                for line in lines:
                    self.daily_tasks_list.insert(tk.END, line.strip())  # strip()
        except FileNotFoundError:
            messagebox.showwarning("文件未找到", "未找到memo.txt文件,请确保文件存在。")
        try:
            # 读取txt文件内容
            if not os.path.exists(file_path1):
                # 如果文件不存在,则创建它
                with open(file_path1, 'w') as file:
                    file.write('')
            with open(file_path2, "r") as file:  #"E:\每日必做.txt"
                #content = file.read()
                lines = file.readlines()
                for line in lines:
                    self.memo_list.insert(tk.END, line.strip())  # strip()

        except FileNotFoundError:
            messagebox.showwarning("文件未找到", "未找到memo.txt文件,请确保文件存在。")

    # 主程序入口

if __name__ == "__main__":
    app = MemoApp()
    app.mainloop()
'''

效果图

效果图
微信图片_20240325103209.png 微信图片_20240325103215.png

免费评分

参与人数 9吾爱币 +13 热心值 +9 收起 理由
5Axi + 1 我很赞同!
orangeidea + 1 我很赞同!
timeni + 1 + 1 用心讨论,共获提升!
爱飞的猫 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
catti518 + 1 + 1 我很赞同!
vethenc + 1 + 1 谢谢@Thanks!
peiki + 1 + 1 热心回复!
0120 + 1 + 1 用心讨论,共获提升!
黄色土豆 + 1 + 1 加油,成长是路程是艰难的。

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| phantomxjc 发表于 2024-3-25 10:53
78zhanghao87 发表于 2024-3-25 10:47
这么说自己做的软件么?笑死

自己的孩子随便怎么说哈哈哈
不知道改成啥 发表于 2024-3-25 10:46
78zhanghao87 发表于 2024-3-25 10:47
土鸡炖蘑菇 发表于 2024-3-25 10:51
用QT做ui 会好看些
 楼主| phantomxjc 发表于 2024-3-25 10:52

qt打包出来太大了没办法
sai609 发表于 2024-3-25 10:58
备忘录,txt或者纸质手写即可
sihehe 发表于 2024-3-25 11:01
学习一下,喜欢动手的楼主
wwd2018 发表于 2024-3-25 11:01
对小白来说,都是高手呀
1smile 发表于 2024-3-25 11:03
还好没在吃饭
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-31 16:51

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表