Query window & SQLite database

Tkinter SQLite SQLite Connector Part -1 Part -3

Query window for SQlite connector

Tkinter child window using Toplevel to execute user entered SQL query on SQLite and display result

Opening Query window

We will use the Query button to execute the function my_child() to open the child window. Inside this function we will display the Text to collect the user entered SQL.
def my_child():
    t1_child=tk.Text(my_w_child, bg='yellow',height=5,width=45)
    t1_child.insert(tk.END, sql_str.get()) # to retain the query while opening 
    b3=tk.Button(my_w_child,text='Submit', command=lambda:child_close())
    def child_close():
        sql_str.set(t1_child.get("1.0",'end-1c')) # collect the query
        my_data(t1_child.get("1.0",'end-1c')) # pass the query 
        my_w_child.destroy() # close the child window
On click of submit button on child window, we will execute another function child_close() to close the child window and pass the user entered query to another function my_data(). After sending the data we will close the child window.

Executing the query : my_data()

Our function my_data() will receive the query and first it will delete the previous data if any in our main display Text area . Then set the background to white by using config()

We will find out the type of query user has entered, if SELECT word is present then show all the records.

Using one try except code block run the query and set the result.

Finally we will display the result.

The connection to SQLite ( the connection.py file ) is available in Part -1 of SQlite connector. connector-sqlite-part-2
SQLite Connector Part -1 ( Browse and connect OR create database ) SQLite Connector Part -3 (Run Queries)
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net


    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2022 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer