Sep-13-2021, 09:11 AM
This is with sqlite3 but queries are the same
#! /usr/bin/env python3 import sqlite3 import tkinter as tk conn = sqlite3.connect('test.db') cursor = conn.cursor() cursor.execute('drop table if exists test_table') conn.commit() conn = sqlite3.connect('test.db') cursor = conn.cursor() table = '''create table test_table( id integer primary key autoincrement not null, name varchar(100) not null )''' conn.execute(table) conn.commit() names = [(1,'tom'), (2, 'harry'), (3, 'john'),(4, 'mary'), (5, 'pam')] conn = sqlite3.connect('test.db') cursor = conn.cursor() cursor.executemany('insert into test_table (id, name) values (?, ?)', names) conn.commit() count = cursor.execute('select count(*) from test_table') next_num = count.fetchall()[0][0] conn.close() root = tk.Tk() var = tk.IntVar() var.set(next_num+1) field1 = tk.Entry(root, text=var, width=5) field1.grid(column=0, row=0) field2 = tk.Entry(root, width=20) field2.grid(column=1, row=0) label = tk.Label(root, text=f'Current entries: {var.get()-1}') label.grid(column=0, row=1, sticky='w') btn = tk.Button(root, text='Submit') btn.grid(column=1, row=1, sticky='e') root.mainloop()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags