Python 3 Tkinter tkmagicgrid Library to Display Colorful Tables Layout From CSV File GUI Desktop App Full Project For Beginners

 

 

pip install tkmagicgrid

 

 

First of all you need to make a test.csv file and copy paste the following code

 

 

test.csv

 

 

name,age,subject
gautam,12,maths
suraj,13,science

 

 

Now you need to make an app.py file and copy paste the following code

 

 

app.py

 

 

#!/usr/bin/env python3

from tkinter import *
from tkmagicgrid import *
import io
import csv

# Create a root window
root = Tk()

# Create a MagicGrid widget
grid = MagicGrid(root)
grid.pack(side="top", expand=1, fill="both")

# Display the contents of some CSV file
# (note this is not a particularly efficient viewer)
with io.open("test.csv", "r", newline="") as csv_file:
    reader = csv.reader(csv_file)
    parsed_rows = 0
    for row in reader:
        if parsed_rows == 0:
            # Display the first row as a header
            grid.add_header(*row)
        else:
            grid.add_row(*row)
        parsed_rows += 1

# Start Tk's event loop
root.mainloop()

 

 

 

Leave a Reply