Example 1: tk table python
try:
from tkinter import *
except ImportError:
from Tkinter import *
root = Tk()
height = 5
width = 5
for i in range(height):
for j in range(width):
b = Entry(root, text="")
b.grid(row=i, column=j)
mainloop()
Example 2: how to create table in tkinter
from tkinter import *
class Table:
def __init__(self,root_2):
global results
for i in range(l):
for j in range(5):
exec(f"self.e{i}_{j} = Entry(root_2,width=20,fg='blue',font=('Arial',16,'bold'))")
exec(f"self.e{i}_{j}.grid(row={i}+2,column={j})")
exec("self.e"+str(i)+"_"+str(j)+".insert(END, results["+str(i)+"]["+str(j)+"])")
results = [['1001','SID','CS','100000','18'],['1002','KRISH','BioTech','100000','18'],['1003','GEM','CS','100000','18']]
l = len(results)
root_2 = Tk()
root_2.title('Details')
text = Label(root_2,text = "EMPLOYEE DETAILS", font=('Atial',18,'bold')).grid(row=0,column=2)
text = Label(root_2,text = "ID", font=('Atial',16,'bold')).grid(row=1,column=0,sticky=W)
text = Label(root_2,text = "Name", font=('Atial',16,'bold')).grid(row=1,column=1,sticky=W)
text = Label(root_2,text = "Department", font=('Atial',16,'bold')).grid(row=1,column=2,sticky=W)
text = Label(root_2,text = "Salary", font=('Atial',16,'bold')).grid(row=1,column=3,sticky=W)
text = Label(root_2,text = "Age", font=('Atial',16,'bold')).grid(row=1,column=4,sticky=W)
t = Table(root_2)
root_2.mainloop()