Skip to main content

entry with listbox and database

 Here in this coding we are going to see the entry attached with listbox and database of sqlite 3

so here is the coding to as follows




========================================================================

from tkinter import *
import sqlite3

root = Tk()
root.title('Codemy.com - Auto Select/Search')

root.geometry("500x300")

# Update the listbox
def update(data):
    # Clear the listbox
    my_list.delete(0, END)

    # Add toppings to listbox
    for item in data:
        my_list.insert(END, item)

# Update entry box with listbox clicked
def fillout(e):
    # Delete whatever is in the entry box
    my_entry.delete(0, END)

    # Add clicked list item to entry box
    my_entry.insert(0, my_list.get(ANCHOR))
    my_list.forget()#here forget will work because re-entry can be done by deleting
    the items.

# Create function to check entry vs listbox
def check(e):

    #grab what was typed
    typed = str(my_entry.get())
    my_list.pack()
    if typed == '':
        data = toppings
    else:
        data = []
        for item in toppings:
            if typed.lower() in item.lower():
                data.append(item)

    # update our listbox with selected items
    update(data)


# Create a label
my_label = Label(root, text="Start Typing...",
    font=("Helvetica", 14), fg="grey")

my_label.pack(pady=20)

# Create an entry box
my_entry = Entry(root, font=("Helvetica", 20))
my_entry.pack()

# Create a listbox
my_list = Listbox(root, width=50)


# Create a list of pizza toppings
conn = sqlite3.connect('society_data.db')
conn.row_factory = lambda cursor, row: row[1]
c = conn.cursor()
c.execute("SELECT code,dcs_name FROM society_data")
rows = c.fetchall()
# load the listbox with data
for item in rows:
    my_list.insert(END, str(item).replace("(", "").replace(")", "").replace("'", ""))
toppings=rows
# Add the toppings to our rows
update(toppings)

# Create a binding on the listbox onclick
my_list.bind("<<ListboxSelect>>", fillout)

# Create a binding on the entry box
my_entry.bind("<KeyRelease>", check)

root.mainloop()

Comments

Popular posts from this blog

Creating designed pages in tkinter

Here in this blog we can make the creative pages in tkinter for the entry section   So here are the following codes for that:- from tkinter import * user_form = Tk () user_form . geometry ( "750x450" ) user_form . title ( "Register form" ) user_form . resizable ( 0 , 0 ) pic1 = PhotoImage ( file = "user_form.png" ) user_form1 = Label ( user_form , image = pic1 , width = 750 , height = 450 ) user_form1 .image= pic1 user_form1 . pack () name_en = Entry ( user_form , width = 14 , relief = "flat" , font =( "times" , 20 )) name_en . place ( relx = 0.385 , rely = 0.265 ) user_en = Entry ( user_form , width = 19 , relief = "flat" , font =( "times" , 20 )) user_en . place ( relx = 0.385 , rely = 0.365 ) psswd_en = Entry ( user_form , width = 18 , relief = "flat" , font =( "times" , 20 )) psswd_en . place ( relx = 0.385 , rely = 0.485 ) pic3 = PhotoImage ( file = "register.png" ) but1 = Button...

entry box with the automatic listbox

 Here in this coding we are going to show the entry connected with the listbox in python. so here is the following coding as respective to the needs. ========================================================================= import tkinter as tk def on_change (* args ):     # print(args)     value = var_text . get ()     value = value . strip (). lower ()     # get data from test_list     if value == '' :         data = test_list     else :         data = []         for item in test_list :             if value in item . lower ():                 data . append ( item )                 # update data in listbox     listbox_update ( data ) def listbox_update ( data ):     # delete previous data     listbox . delete...

How to make form in HTML?

  Here in this blog, we are providing the programming codes for making an HTML form. so here are the following codes:- <! DOCTYPE html > < html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta http-equiv = "X-UA-Compatible" content = "IE=edge" >     < meta name = "viewport" content = "width=device-width, initial-scale=1.0" >     < title > forms </ title > </ head > < body >     < h2 > this is form tutorial </ h2 >     < form action = "backend.php" >         <!-- yaha par bas input type karo aur ek list dikhayga aur jo daalna           hai select kar lo -->       <!-- here label works that if label for="name" and id ="name" than if we           will click on name on html web page than the cursor will go on the  ...