I am writing a program that saves user data. It is necessary to write code for the “Save” buttons so that the data entered by the user is saved (preferably in a sqlite3 database). I just understood Tkinter, I still have to deal with the database SQLite, but I don’t have time. Help quickly please. I see that everyone is just writing databases, but I can’t understand them yet, but I need to finish my micro project by tomorrow.
import tkinter as tk
from tkinter import messagebox
import sqlite3 as sql
win = tk.Tk()
win.title('Saver data')
win.geometry('390x310')
win.resizable(False, False)
def delete_catalog():
selection = catalogs_listbox.curselection()
try:
catalogs_listbox.delete(selection[0])
except IndexError:
messagebox.showinfo('Attention!', 'Choose element you want to remove')
def add_catalog():
new_catalog = catalog_entry.get()
if len(new_catalog) > 0:
catalogs_listbox.insert(0, new_catalog)
catalog_entry.delete(0, tk.END)
if len(new_catalog) == 0:
messagebox.showinfo('Attention!', 'Enter the folder name!')
intro = tk.Label(text='')
intro.configure(font=('Times New Roman', 11))
intro.place(x=5, y=5)
catalog_entry = tk.Entry(width=21)
catalog_entry.configure(font=('Times New Roman', 15))
catalog_entry.place(x=51, y=30)
add_catalog_btn = tk.Button(text="Add", width=9, command=add_catalog)
add_catalog_btn.place(y=30, x=268)
catalogs_listbox = tk.Listbox(width=29, height=9)
catalogs_listbox.configure(font=('Times New Roman', 15))
catalogs_listbox.place(x=49, y=60)
def on_select(event):
widget = event.widget
selection = widget.curselection()
i = int(widget.curselection()[0])
value = widget.get(i)
if selection:
data_window = tk.Tk()
data_window.title(f'Data for {value}')
data_window.geometry('390x65')
data_window.resizable(False, False)
login_label = tk.Label(master=data_window, text='Login')
login_label.place(x=15, y=5)
login_entry = tk.Entry(master=data_window, width=30)
login_entry.place(x=100, y=5)
password_label = tk.Label(master=data_window, text='Password')
password_label.place(x=15, y=35)
password_entry = tk.Entry(master=data_window, width=30)
password_entry.place(x=100, y=35)
save_datas = tk.Button(master=data_window, text='Save')
save_datas.place(x=300, y=15)
data_window.mainloop()
catalogs_listbox.bind('<<ListboxSelect>>', on_select)
save_program = tk.Button(master=win, text='Save')
save_program.place(x=200, y=278)
scrollbar = tk.Scrollbar(orient=tk.VERTICAL, command=catalogs_listbox.yview)
scrollbar.grid_forget()
catalogs_listbox["yscrollcommand"] = scrollbar.set
delete_catalog = tk.Button(text="Delete", command=delete_catalog)
delete_catalog.configure(font=('Times New Roman', 10))
delete_catalog.place(x=286, y=278)
win.mainloop()
New contributor
pomalllka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.