首页 > 其他分享 >33

33

时间:2024-05-22 22:07:29浏览次数:19  
标签:33 self events time date event conn

今天编程四个小时,用python做了一个日历记事本

import tkinter as tk

from tkinter import messagebox

from tkinter import ttk

from datetime import datetime

import sqlite3

 

def init_db():

    conn = sqlite3.connect('calendar.db')

    c = conn.cursor()

    c.execute('''CREATE TABLE IF NOT EXISTS events

                 (id INTEGER PRIMARY KEY,

                  title TEXT,

                  description TEXT,

                  date TEXT,

                  time TEXT)''')

    conn.commit()

    conn.close()

 

def add_event(title, description, date, time):

    conn = sqlite3.connect('calendar.db')

    c = conn.cursor()

    c.execute("INSERT INTO events (title, description, date, time) VALUES (?, ?, ?, ?)", (title, description, date, time))

    conn.commit()

    conn.close()

 

def edit_event(event_id, title, description, date, time):

    conn = sqlite3.connect('calendar.db')

    c = conn.cursor()

    c.execute("UPDATE events SET title = ?, description = ?, date = ?, time = ? WHERE id = ?", (title, description, date, time, event_id))

    conn.commit()

    conn.close()

 

def delete_event(event_id):

    conn = sqlite3.connect('calendar.db')

    c = conn.cursor()

    c.execute("DELETE FROM events WHERE id = ?", (event_id,))

    conn.commit()

    conn.close()

 

def get_events():

    conn = sqlite3.connect('calendar.db')

    c = conn.cursor()

    c.execute("SELECT * FROM events")

    events = c.fetchall()

    conn.close()

    return events

 

def check_overlapping_events(title, date, time):

    conn = sqlite3.connect('calendar.db')

    c = conn.cursor()

    c.execute("SELECT * FROM events WHERE date = ? AND time = ?", (date, time))

    existing_events = c.fetchall()

    conn.close()

    if len(existing_events) > 0:

        messagebox.showwarning("警告", "存在过于紧张的日程安排")

 

class CalendarApp:

    def __init__(self, root):

        self.root = root

        self.root.title("日历记事本")

        self.create_widgets()

        

    def create_widgets(self):

        # Main Frame

        main_frame = ttk.Frame(self.root, padding="10")

        main_frame.pack(fill=tk.BOTH, expand=True)

        

        # Title Entry

        self.title_label = ttk.Label(main_frame, text="标题  ")

        self.title_label.grid(row=0, column=0, sticky=tk.W, pady=5)

        self.title_entry = ttk.Entry(main_frame)

        self.title_entry.grid(row=0, column=1, sticky=tk.EW, pady=5)

        

        # Description Entry

        self.description_label = ttk.Label(main_frame, text="描述  ")

        self.description_label.grid(row=1, column=0, sticky=tk.W, pady=5)

        self.description_entry = ttk.Entry(main_frame)

        self.description_entry.grid(row=1, column=1, sticky=tk.EW, pady=5)

        

        # Date Entry

        self.date_label = ttk.Label(main_frame, text="日期  ")

        self.date_label.grid(row=2, column=0, sticky=tk.W, pady=5)

        self.date_entry = ttk.Entry(main_frame)

        self.date_entry.insert(0, datetime.now().strftime('%Y-%m-%d'))  # Default to current date

        self.date_entry.grid(row=2, column=1, sticky=tk.EW, pady=5)

        

        # Time Entry

        self.time_label = ttk.Label(main_frame, text="时间  ")

        self.time_label.grid(row=3, column=0, sticky=tk.W, pady=5)

        self.time_entry = ttk.Entry(main_frame)

        self.time_entry.insert(0, datetime.now().strftime('%H:%M'))  # Default to current time

        self.time_entry.grid(row=3, column=1, sticky=tk.EW, pady=5)

        

        # Button Frame

        button_frame = ttk.Frame(main_frame, padding="10")

        button_frame.grid(row=4, column=0, columnspan=2, pady=10)

        

        # Add Event Button

        self.add_button = ttk.Button(button_frame, text="添加事件", command=self.add_event)

        self.add_button.pack(side=tk.LEFT, padx=5)

        

        # View Events Button

        self.view_button = ttk.Button(button_frame, text="查看事件", command=self.view_events)

        self.view_button.pack(side=tk.LEFT, padx=5)

        

        # Edit Event Button

        self.edit_button = ttk.Button(button_frame, text="编辑事件", command=self.edit_event)

        self.edit_button.pack(side=tk.LEFT, padx=5)

        

        # Delete Event Button

        self.delete_button = ttk.Button(button_frame, text="删除事件", command=self.delete_event)

        self.delete_button.pack(side=tk.LEFT, padx=5)

        

        

        

        # Configure grid weights

        main_frame.columnconfigure(1, weight=1)

        

    def add_event(self):

        title = self.title_entry.get()

        description = self.description_entry.get()

        date = self.date_entry.get()

        time = self.time_entry.get()

        

        # Add the event to the database

        add_event(title, description, date, time)

        

        # Check for overlapping events

        check_overlapping_events(title, date, time)

 

    def view_events(self):

        events = get_events()

        event_list = "\n".join([f"ID: {event[0]}, 标题: {event[1]}, 描述: {event[2]}, 日期: {event[3]}, 时间: {event[4]}" for event in events])

        messagebox.showinfo("事件列表", event_list)

        

    def edit_event(self):

        pass

        

    def delete_event(self):

        pass

 

# Initialize database and create table if not exists

init_db()

 

root = tk.Tk()

app = CalendarApp(root)

root.mainloop()

标签:33,self,events,time,date,event,conn
From: https://www.cnblogs.com/yuanxinglan/p/18207245

相关文章

  • ABC337
    基本情况ABC秒了,D数组在空间复杂度上面第一次疯狂吃亏,吃了两次罚时过。赛后看官方题解,发现C做法薄纱我。C-LiningUp2https://atcoder.jp/contests/abc337/tasks/abc337_c这题一眼链表,我用双向链表实现,代码石山。官方题解就题论题,更本质。其实这题并没必要开双向链......
  • 深度学习吴恩达学习记录 133-140
    目标定位:对于图像上的目标,如果进行识别后还需要将其在图上进行框出,我们就要多训练几个数据,一个就是识别目标的中心点,另外一个就是我设置圈出的长与宽可以记为bx,by,bh,bw;根据训练出的模型在图像检测上预测出这四个点的位置,当物体出现的时候就可以根据这个数据进行定位。当然要做......
  • U433730 为了人类的未来,让我们做离散数学上机题吧
    为了人类的未来,让我们做离散数学上机题吧题目背景李昕峰同学致力于研究可控核聚变技术,每天废寝忘食,呕心沥血,抽不出空写离散作业。你身为李昕峰的同学,为了国家的未来,为了人类科技的发展,为了以后人类能够安全有效地使用核能,你需要帮助李昕峰同学完成他的离散作业。你不需要写很多,......
  • 3326:练55.1 合影效果
    【题目描述】小明和朋友们去爬香山,为美丽的景色所陶醉,想合影留念。如果他们站成一排,男生全部在左(从拍照者的角度),并按照从矮到高的顺序从左到右排,女生全部在右,并按照从高到矮的顺序从左到右排,请问他们合影的效果是什么样的(所有人的身高都不同)?【输入】第一行是人数n(2≤n≤40,且......
  • RK3308 SDK 编译 --- ubuntu 22
    ./build.shbuildroot编译问题controller-enumtypes.c:6:1:error:stray'\'inprogram\#include"gstinterpolationcontrolsource.h"^controller-enumtypes.c:6:2:error:stray'#'inprogram\#include"gstinterpolationco......
  • 《安富莱嵌入式周报》第337期:超高性能信号量测量,协议分析的开源工具且核心算法开源,工
    周报汇总地址:http://www.armbbs.cn/forum.php?mod=forumdisplay&fid=12&filter=typeid&typeid=104 视频版:https://www.bilibili.com/video/BV1PT421S7TR/目录1、一款超高性能信号量测量,协议分析的开源跨平台上位机工具ngscopeclient,核心算法全开源2、ST推出面向工业安全......
  • Vue3报错:已声明“upperName”,但从未读取其值。ts-plugin(6133)
    Vue3报错:已声明“upperName”,但从未读取其值。ts-plugin(6133)报错显示:类型“StoreToRefs<Store<"count",{sum:number;name:string;address:string;},{},{increment(value:number):void;}>>”上不存在属性“upperName”。ts-plugin(2339)相关代码:vue文件:con......
  • 记录freeswitch的一个2833问题
    概述freeswitch是一款简单好用的VOIP开源软交换平台。运营商内部新老系统混用,互联互通的问题较多,其中以DTMF码的问题最多,花样也多。环境CentOS7.9freeswitch1.10.7问题描述问题现象正常的fs业务服务器,呼叫正常,部分呼叫报错DTMF收码失败。内部测试,呼叫正常,信令正常,媒体......
  • P3366 【模板】最小生成树
    链接:https://www.luogu.com.cn/problem/P3366模板题:kruskal代码:核心是对边的排序,遍历,选择。#include<iostream>#include<vector>#include<algorithm>#include<math.h>#include<sstream>#include<string>#include<string.h>#include<......
  • 题解:CF1337A Ichihime and Triangle
    看到大佬们基本都是直接输出\(b\)\(c\)\(c\)了事儿,一身反骨有其它构造方法的我表示不服,遂作此篇。众所周知,两边之和大于第三边,所以,如果\(b+c>d\),那么\(b\)、\(c\)、\(d\)就是正确的。那如果不满足呢?在题目条件下\(b+c>b+c-1\),那么这一组就是合理的。分别验......