May-25-2023, 06:30 AM
I've corrected the code for you to look over.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import tkinter as tk 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 14" ] #For test, usually empty _alist = [] root = tk.Tk() root[ 'padx' ] = 5 root[ 'pady' ] = 5 root.title( 'Feed Bins' ) root.geometry( "1200x900" ) root.columnconfigure( 0 , weight = 1 ) root.rowconfigure( 0 , weight = 1 ) frame = tk.Frame(root) frame[ 'highlightbackground' ] = 'black' frame[ 'highlightcolor' ] = 'black' frame[ 'highlightthickness' ] = 1 frame.grid(column = 0 , row = 0 , sticky = 'nsew' , padx = 5 , pady = 5 ) i = 0 for x in range ( 5 ): frame.grid_rowconfigure(x, weight = 3 , uniform = 'rows' ) for y in range ( 3 ): frame.grid_columnconfigure(y, weight = 3 , uniform = 'cols' ) label = _alist.append(tk.Label(frame, text = aList[x + (y * 5 )], relief = 'raised' , font = ( None , 16 , 'bold' ))) _alist[i][ 'bg' ] = 'red' if _alist[i] in onList else 'gray86' _alist[i].grid(column = y, row = x, sticky = 'nsew' , padx = 5 , pady = 5 ) i + = 1 #check_alerts() btn = tk.Button(root, text = 'Add item to onList' , font = ( None , 14 , 'bold' ), command = lambda : [onList.append( "Bin 9" ), print ( "Button Press" )]) btn.grid(column = 0 , row = 1 ) def check_alerts(): for x in range ( 0 , len (_alist)): if _alist[x][ 'text' ] in onList: _alist[x][ 'bg' ] = 'red' else : _alist[x].config(bg = "lightgrey" ) root.after( 1000 ,check_alerts) root.after( 1000 , check_alerts) 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
Download my project scripts
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts