Jul-11-2020, 08:01 PM
(This post was last modified: Jul-11-2020, 08:02 PM by kenwatts275.)
Hello all,
I cannot seem to get the column headers to align properly with my table.
The column headers have to be in a separate frame than the table, because I will be adding a scrollbar on the table. Below is a screenshot of the output and the code.
Any help would be appreciated.
Thanks in advance.
![[Image: UzkCoCT]](https://imgur.com/gallery/UzkCoCT)
I cannot seem to get the column headers to align properly with my table.
The column headers have to be in a separate frame than the table, because I will be adding a scrollbar on the table. Below is a screenshot of the output and the code.
Any help would be appreciated.
Thanks in advance.
from tkinter import *
from tkinter import ttk
from pathlib import Path
def data_table(frame,col_widths):
# Create and populate values array
for i in range(0,max_rows):
values.append([])
j = 0
values[i].append(StringVar())
cb = ttk.Combobox(frame,width=col_widths[j],textvariable=values[i][j])
cb.grid(row=i, column= j)
j += 1
values[i].append(StringVar())
ent = Entry(frame,width=col_widths[j],textvariable=values[i][j])
ent.grid(row=i, column= j)
j += 1
values[i].append(StringVar())
ent = Entry(frame,width=col_widths[j],textvariable=values[i][j])
ent.grid(row=i, column= j)
j += 1
values[i].append(BooleanVar()) # readonly
cb = ttk.Checkbutton(frame,width=col_widths[j],onvalue=1,offvalue=0,variable=values[i][j])
cb.grid(row=i, column= j)
j += 1
values[i].append(BooleanVar()) # Copy
cb = ttk.Checkbutton(frame,width=col_widths[j],onvalue=1,offvalue=0,variable=values[i][j])
cb.grid(row=i, column= j)
j += 1
values[i].append(BooleanVar()) # mandatory
cb = ttk.Checkbutton(frame,width=col_widths[j],onvalue=1,offvalue=0,variable=values[i][j])
cb.grid(row=i, column= j)
j += 1
values[i].append(StringVar()) # sort order
ent = Entry(frame,width=col_widths[j],textvariable=values[i][j])
ent.grid(row=i, column= j)
j += 1
values[i].append(BooleanVar()) # removed
cb = ttk.Checkbutton(frame,width=col_widths[j],onvalue=1,offvalue=0,variable=values[i][j])
cb.grid(row=i, column= j)
if __name__ == "__main__":
current_file = Path(__file__).stem
mw=Tk()
mw.geometry('1000x500+200+150')
mw.title(current_file)
frame4 = Frame(mw)
frame5 = Frame(mw)
frame4.pack(side=TOP,fill=X)
frame5.pack(side=TOP,fill=X)
headers = ["Field Name","Field Label","Default Value","ReadOnly","Copy","Mandatory","Sort Order","Remove"]
col_widths = [20,20,20,8,8,8,10,6]
column = 0
for header in headers:
l1 = Label(frame4,relief=FLAT,width=col_widths[column],text=header,anchor="w",justify="left")
l1.grid(row=0,column= column)
column += 1
values = []
max_rows = 10
data_table(frame5,col_widths)
mw.mainloop()
