TO-DO LIST APP WITH SQL DATABASE
Source Code:-
01 02 03 04 05 06 07 08 09 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 | # To-Do List App with SQL database # create a Database firstly to RUN this Code # database creating command:- " create database todo_list; " from tkinter import * from tkinter import messagebox as msg import mysql.connector root = Tk() # Download icons in '.ico' format from "https://iconarchive.com/" root.iconbitmap( "D:/PYTHON MODULES/TKINTER/TKINTER PROJECTS/ICONs/To-Do List.ico" ) root.geometry( '450x500+450+80' ) root.title( "TO-DO LIST APP" ) root.config(bg = '#437481' ) root.resizable( 0 , 0 ) db = mysql.connector.connect( host = "localhost" , user = "root" , password = "**********" , database = "todo_list" ) cur = db.cursor() cur.execute( "create table IF NOT EXISTS todo(SrNo int NOT NULL PRIMARY KEY, Task varchar(50))" ) db.commit() count = 0 def add_task(): global count count = count + 1 add = my_task.get() if add ! = "": lbox.insert(END, add) my_task. set ("") insert_data = "insert into todo(SrNo, Task) Values(%s, %s)" data = [(count, add)] cur.executemany(insert_data, data) db.commit() msg.showinfo( "Saved" , "Your Task Added Successfully." ) else : msg.showwarning( "Warning" , "Please Enter a Task." ) def del_one(): for i in lbox.curselection(): cur.execute( "delete from todo where Task = '%s'" % (lbox.get(i))) db.commit() lbox.delete(i) msg.showinfo( "Deleted" , "Your Selected Task Delete Successfully." ) break else : msg.showwarning( "Warning" , "Please Select a Task to Delete." ) def del_all(): del_item = "delete from todo" cur.execute(del_item) db.commit() lbox.delete( 0 , END) msg.showinfo( "Deleted" , "Your All Task Delete Successfully." ) frame = Frame(root) frame.place(x = 65 , y = 20 ) lbox = Listbox(frame, width = 26 , height = 8 , font = ( "Times 18 bold" ), bg = "khaki" , selectbackground = '#a6a436' , activestyle = "none" , relief = GROOVE) lbox.pack(side = LEFT, fill = BOTH) sb = Scrollbar(frame) sb.pack(side = RIGHT, fill = BOTH) lbox.config(yscrollcommand = sb. set ) sb.config(command = lbox.yview) Label(root, text = "Enter Task:" , font = ( "None 17 bold" ), bg = '#437481' ).place(x = 5 , y = 282 ) my_task = StringVar() Entry(root, textvariable = my_task, font = ( "None 20 bold" )).place(x = 140 , y = 280 ) Button(root, text = 'Add Task' , font = ( 'Times 18 bold' ), bg = '#c5f776' , command = add_task).place(x = 90 , y = 350 ) Button(root, text = 'Delete Task' , font = ( 'Times 18 bold' ), bg = '#ff8b61' , command = del_one).place(x = 235 , y = 350 ) Button(root, text = 'Delete All' , font = ( 'Times 18 bold' ), bg = '#a84587' , command = del_all).place(x = 87 , y = 430 ) Button(root, text = 'Exit' , font = ( 'Times 18 bold' ), bg = '#848732' , command = exit).place(x = 270 , y = 430 ) root.mainloop() |
# To-Do List App with SQL database # create a Database firstly to RUN this Code # database creating command:- " create database todo_list; " from tkinter import * from tkinter import messagebox as msg import mysql.connector root = Tk() # Download icons in '.ico' format from "https://iconarchive.com/" root.iconbitmap("D:/PYTHON MODULES/TKINTER/TKINTER PROJECTS/ICONs/To-Do List.ico") root.geometry('450x500+450+80') root.title("TO-DO LIST APP") root.config(bg='#437481') root.resizable(0, 0) db = mysql.connector.connect( host = "localhost", user = "root", password = "**********", database = "todo_list") cur = db.cursor() cur.execute("create table IF NOT EXISTS todo(SrNo int NOT NULL PRIMARY KEY, Task varchar(50))") db.commit() count = 0 def add_task(): global count count = count + 1 add = my_task.get() if add != "": lbox.insert(END, add) my_task.set("") insert_data = "insert into todo(SrNo, Task) Values(%s, %s)" data = [(count, add)] cur.executemany(insert_data, data) db.commit() msg.showinfo("Saved", "Your Task Added Successfully.") else: msg.showwarning("Warning", "Please Enter a Task.") def del_one(): for i in lbox.curselection(): cur.execute("delete from todo where Task = '%s'"%(lbox.get(i))) db.commit() lbox.delete(i) msg.showinfo("Deleted", "Your Selected Task Delete Successfully.") break else: msg.showwarning("Warning", "Please Select a Task to Delete.") def del_all(): del_item = "delete from todo" cur.execute(del_item) db.commit() lbox.delete(0, END) msg.showinfo("Deleted", "Your All Task Delete Successfully.") frame = Frame(root) frame.place(x = 65, y = 20) lbox = Listbox(frame, width=26, height=8, font=("Times 18 bold"), bg = "khaki", selectbackground='#a6a436', activestyle="none", relief=GROOVE) lbox.pack(side=LEFT, fill=BOTH) sb = Scrollbar(frame) sb.pack(side=RIGHT, fill=BOTH) lbox.config(yscrollcommand=sb.set) sb.config(command=lbox.yview) Label(root, text="Enter Task:", font=("None 17 bold"), bg='#437481').place(x = 5, y = 282) my_task = StringVar() Entry(root, textvariable=my_task, font=("None 20 bold")).place(x = 140, y = 280) Button(root, text='Add Task', font=('Times 18 bold'), bg='#c5f776', command=add_task).place(x = 90, y = 350) Button(root, text='Delete Task', font=('Times 18 bold'), bg='#ff8b61', command=del_one).place(x = 235, y = 350) Button(root, text='Delete All', font=('Times 18 bold'), bg='#a84587', command=del_all).place(x = 87, y = 430) Button(root, text='Exit', font=('Times 18 bold'), bg='#848732', command=exit).place(x = 270, y = 430) root.mainloop()
0 Comments