Python Forum
Column headers not aligning properly with table
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Column headers not aligning properly with table
#2
Maybe this will get you started in the right direction.
#! /usr/bin/env python3
import tkinter as tk

root = tk.Tk()

root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)

mainframe = tk.Frame(root)
mainframe.grid(column=0, row=0, sticky='new')
mainframe.grid_columnconfigure(0, weight=3)

frame1 = tk.Frame(mainframe)
frame1.grid(column=0, row=0, sticky='new')
for i in range(1,4):
    frame1.grid_columnconfigure(i, weight=3, uniform='columns')



for i in range(1, 4):
    header = tk.Label(frame1, text=f'Header {i}')
    header['relief'] = 'solid'
    header['borderwidth'] = 1
    header['highlightthickness'] = 1
    header['highlightbackground'] = 'grey65'
    header.grid(column=i, row=0, sticky='ew')

frame2 = tk.Frame(mainframe)
frame2.grid(column=0, row=1, sticky='new')
for i in range(1, 4):
    frame2.columnconfigure(i, weight=3, uniform='table')

table_data = ['This is some data for row 1', 'Data for row 2', 'Data for row 3. This could be anything']

column = 1
for tdata in table_data:
    data = tk.Label(frame2, text=tdata)
    data['relief'] = 'solid'
    data['borderwidth'] = 1
    data['highlightthickness'] = 1
    data['highlightbackground'] = 'grey65'
    data.grid(column=column, row=0, sticky='ew')
    column += 1

root.mainloop()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
RE: Column headers not aligning properly with table - by menator01 - Jul-11-2020, 09:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Aligning Python Tkinter Buttons In Rows TollyThaWally 3 8,107 Feb-22-2018, 02:56 AM
Last Post: woooee
  which column of sql table is equal to a variable gray 7 6,145 Mar-20-2017, 04:11 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020