Java, Python, Database, Flutter, Matlap, Micorcontroller, Tutorials, Swing Framework

Hancie e-Learning Studio

Learn Java, Learn HTML, CSS, PHP, Javascript, Python Tutorials || Download program source codes || Java Project and Source code available here || All types error troubleshooting tips available here

How to insert MySQL data values in Tkinter Treeview?

 


connection.py
import mysql.connector
import sys

def Connect():
    conn=None
    try:
        conn=mysql.connector.connect(
            host='localhost',
            username='root',
            password='',
            database='taxi_booking_system'
        )

    except:
        print("Error", sys.exc_info())

    finally:

        return conn

backend.py
import sys
from dbms.connection import Connect


def select_all720():
    conn=None
    sql="""SELECT * FROM booking"""
    Bookresult=None
    try:
        conn=Connect()
        cursor=conn.cursor()
        cursor.execute(sql)
        Bookresult=cursor.fetchall()
        cursor.close()
        conn.close()


    except:
        print("Error", sys.exc_info())

    finally:
        del sql, conn
        return Bookresult
gui.py
from tkinter import *
from tkinter import ttk

from dbms.booking_backend import select_all
from test.test2 import select_all720

app=Tk()
app.geometry("500x400")
app.title("Hancie e-Learning Studio")

treeView=ttk.Treeview(app)
treeView.pack()

treeView['columns']=('id', 'pickupaddress','date')
treeView.column('#0', width=0, stretch=0)
treeView.column('id', width=100, anchor=CENTER)
treeView.column('pickupaddress', width=200, anchor=CENTER)
treeView.column('date', width=100, anchor=CENTER)

treeView.heading('#0', text='', anchor=CENTER)
treeView.heading('id', text="ID", anchor=CENTER)
treeView.heading('pickupaddress', text="Pickup address", anchor=CENTER)
treeView.heading('date', text="Date", anchor=CENTER)


def bookingtable():

    Bookresult = select_all720()
    i=0
    for ro in Bookresult:
        treeView.insert(parent='', index='end', values=(ro[0], ro[1], ro[2]))




bookingtable()
app.mainloop()
Output


Welcome all to Hancie e-learning studio
Friends,
I have brought an e-learning platform for you from where you can teach internet, website, programming language, error troubleshooting, etc. Blogger, WordPress templates, themes are available for free on this website, which are not charged for downloading, so that you can earn money by blogging using such templates and this is not a difficult task and this You can do it now. You keep uploading new posts by us and keep taking advantage of this website. The aim of which is to spread the knowledge related to internet, career, web designing and technology to the people and contribute to the development of the country.