Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Add column headings with TKinter grid and centering

Add column headings with TKinter grid and centering

Add column headings with TKinter grid and centering

I'm learning TKinter slowly and trying to use it for a small home project.

I have a grid filled from a Python list, that is working, but I would like to add a top row with column headings, and force the grid to be centered in the window. I have created grids with manually coded rows, having text headings in row 0, but in my grid based on a list I haven't been able to use Row 0 for label text.

As I can learn, I would also like to add (smaller font) centered text line at the bottom of the window, and maybe a push button or two at far right lower corner. See code below.

CODE --> python

import tkinter as tk
import tkinter.font as font
window = tk.Tk()
window.title("Feed Bins")

aList = ["Bin 1", "Bin 2", "Bin 3", "Bin 4", "Bin 5", "Bin 6", "Bin 7", "Bin 8", "Bin 9", "Bin 10", "Bin 11",
        "Bin 12", "Bin 13", "Bin 14", "Bin 15"]
onList = ["Bin 3", "Bin 12", "Bin 14"]

myFont2 = font.Font(size=10)

label= [0] * 15
for x in range(5):    # Number of Rows
   for y in range(3): #Number of Colums
       frame = tk.Frame(master=window,relief=tk.RAISED,borderwidth=4)
       frame.grid(row=x, column=y, padx=5, pady=5)  # line 13
       label[x+(y*5)] = tk.Label(master=frame, text=aList[x+(y*5)],font=myFont2, height=3, width=20)

def check_alerts():
   global aList,onList
   for x in range(0,len(aList)):
       if aList[x] in onList:
           label[x].config(bg = "red")
           label[x].config(bg = "lightgrey")


Any advice greatly appreciated.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close