Query window & SQLite database

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():
    my_w_child=tk.Toplevel(my_w)
    my_w_child.geometry("400x200")
    my_w_child.title('www.plus2net.com')
    
    l1_q=tk.Label(my_w_child,text='Query')
    l1_q.grid(row=1,column=1)
    t1_child=tk.Text(my_w_child, bg='yellow',height=5,width=45)
    t1_child.grid(row=2,column=1,padx=10,columnspan=2)
    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())
    b3.grid(row=3,column=1)
    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


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    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-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer