Python Forum
Auto increament in Entry field. in tkinter GUI
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Auto increament in Entry field. in tkinter GUI
#4
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


Reply


Messages In This Thread
RE: Auto increament in Entry field. in tkinter GUI - by menator01 - Sep-13-2021, 09:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to open a popup window in tkinter with entry,label and button lunacy90 1 974 Sep-01-2023, 12:07 AM
Last Post: lunacy90
  Tkinter Entry size limit vman44 3 7,042 Dec-22-2022, 06:58 AM
Last Post: vman44
  Display value in the another entry field instead of message box adisc 6 1,639 Jun-25-2022, 02:30 PM
Last Post: rob101
  tkinter auto press button kucingkembar 2 3,280 Dec-24-2021, 01:23 PM
Last Post: kucingkembar
  Bug ? when dataclass field name == field type Cyril 0 1,586 Oct-22-2020, 03:26 AM
Last Post: Cyril
  Help pulling tkinter Entry string data Raudert 8 10,145 Jan-12-2017, 11:49 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020