In Python GUI development, storing results in a database is a common task that can be achieved using libraries such as SQLite3 or SQLAlchemy. Here is a simple example demonstrating how to insert data into a SQLite database using a Python GUI application.
import sqlite3
from tkinter import *
# Create a GUI application
root = Tk()
root.title("Database Example")
# Function to insert data into the database
def insert_data():
conn = sqlite3.connect('example.db')
cursor = conn.cursor()
# Create a table
cursor.execute('''CREATE TABLE IF NOT EXISTS results (id INTEGER PRIMARY KEY, name TEXT)''')
# Insert a new record
name = entry.get()
cursor.execute('INSERT INTO results (name) VALUES (?)', (name,))
conn.commit()
cursor.close()
conn.close()
# Clear entry field
entry.delete(0, END)
# GUI layout
entry = Entry(root)
entry.pack()
button = Button(root, text="Insert", command=insert_data)
button.pack()
root.mainloop()
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?