Skip to content

Instantly share code, notes, and snippets.

@jcpst
Last active November 23, 2021 04:44
Show Gist options
  • Save jcpst/aa8db06df70fad3e246f47566923860a to your computer and use it in GitHub Desktop.
Save jcpst/aa8db06df70fad3e246f47566923860a to your computer and use it in GitHub Desktop.
python with gui and db, using standard library.
import sqlite3
from tkinter import *
conn = sqlite3.connect(':memory:')
cursor = conn.cursor()
cursor.execute('create table names (name text)')
def add_name(name):
cursor.execute('insert into names values (?)', (name,))
def get_names():
names = [row[0] for row in cursor.execute('select * from names')]
return ','.join(str(name) for name in names)
window = Tk()
window.geometry('350x200')
window.title("Hi")
def clicked():
add_name(txt.get())
lbl.configure(text=get_names())
txt = Entry(window, width=10)
btn = Button(window, text="Click Me", command=clicked)
lbl = Label(window, text='...', font=("Arial Bold", 12))
txt.grid(column=1, row=0)
btn.grid(column=2, row=0)
lbl.grid(column=0, row=1)
txt.focus()
window.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment