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

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

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

name,age,subject
gautam,12,maths
suraj,13,science
#!/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()
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment