Python Forum
Centering and adding a push button to a grid window, TKinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Centering and adding a push button to a grid window, TKinter
#1
This May be really simple, but I'm not finding enough details to help as I'm just learning TKinter.

I have a simple grid sourced by a Python list, and I'm trying to center it regardless of window size, and add single push button at bottom of the window.
What I have tested caused the full window to grey out.

my code:
import tkinter as tk
from tkinter import *
import tkinter.font as font
window = tk.Tk()
window.title("Feed Bins")
window.geometry("800x400")

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"] # For testing, usually empty

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)
       label[x+(y*5)].pack(fill="x")

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

window.mainloop()   
[Image: gridOnly.png]

Any assistance greatly appreciated.
Reply


Messages In This Thread
Centering and adding a push button to a grid window, TKinter - by Edward_ - May-20-2023, 05:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 726 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  [Tkinter] TKinter Remove Button Frame Nu2Python 8 1,236 Jan-16-2024, 06:44 PM
Last Post: rob101
  tkinter - touchscreen, push the button like click the mouse John64 5 989 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  Tkinter multiple windows in the same window tomro91 1 942 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 2,026 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] Background inactivity timer when tkinter window is not active DBox 4 3,017 Apr-16-2022, 04:04 PM
Last Post: DBox
  [Tkinter] Clicking on the button crashes the TK window ODOshmockenberg 1 2,298 Mar-10-2022, 05:18 PM
Last Post: deanhystad
  why my list changes to a string as I move to another window in tkinter? pymn 4 2,635 Feb-17-2022, 07:02 AM
Last Post: pymn
  Can't get tkinter button to change color based on changes in data dford 4 3,509 Feb-13-2022, 01:57 PM
Last Post: dford
  [Tkinter] Tkinter Window Has no Title Bar gw1500se 4 2,914 Nov-07-2021, 05:14 PM
Last Post: gw1500se

Forum Jump:

User Panel Messages

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