Skip to main content
deleted 3 characters in body
Source Link
Reinderien
  • 71.2k
  • 5
  • 76
  • 257

If there's a list, make it a list

Do not represent RxCx variables as separate variables. Represent them as nested lists and it will greatly simplify your code. Consider grouping them by what makes them similar - column 0 (image_col), columns 1-5 (info_cols) and column 6 (instruction_col) as in the following example:

image_col = [ tk.Button( canv_1, image=root.render1, relief="raised", bg="light gray", command = lambda: change_img(y), ) for y in range(1, 6) ] for y, image_cell in enumerate(image_col, 1): image_cell.grid(row=y, column=0, sticky='news') instruction_col = [ tk.Text( canv_1, bg="white", wrap="word", font=("arial",15), width=20, height=10) ]   for y, image_cell in enumerate(instruction_col , 1): image_cell.grid(row=y, column=6, sticky='news') 

Replace your change_img so that there are no ifs, and everything is done via list lookup from the row index passed. Replace root.img*, root.load_img* and root.render_img* with lists.

If there's a list, make it a list

Do not represent RxCx variables as separate variables. Represent them as nested lists and it will greatly simplify your code. Consider grouping them by what makes them similar - column 0 (image_col), columns 1-5 (info_cols) and column 6 (instruction_col) as in the following example:

image_col = [ tk.Button( canv_1, image=root.render1, relief="raised", bg="light gray", command = lambda: change_img(y), ) for y in range(1, 6) ] for y, image_cell in enumerate(image_col, 1): image_cell.grid(row=y, column=0, sticky='news') instruction_col = [ tk.Text( canv_1, bg="white", wrap="word", font=("arial",15), width=20, height=10) ]   for y, image_cell in enumerate(instruction_col , 1): image_cell.grid(row=y, column=6, sticky='news') 

Replace your change_img so that there are no ifs, and everything is done via list lookup from the row index passed. Replace root.img*, root.load_img* and root.render_img* with lists.

If there's a list, make it a list

Do not represent RxCx variables as separate variables. Represent them as nested lists and it will greatly simplify your code. Consider grouping them by what makes them similar - column 0 (image_col), columns 1-5 (info_cols) and column 6 (instruction_col) as in the following example:

image_col = [ tk.Button( canv_1, image=root.render1, relief="raised", bg="light gray", command = lambda: change_img(y), ) for y in range(1, 6) ] for y, image_cell in enumerate(image_col, 1): image_cell.grid(row=y, column=0, sticky='news') instruction_col = [ tk.Text( canv_1, bg="white", wrap="word", font=("arial",15), width=20, height=10) ] for y, image_cell in enumerate(instruction_col, 1): image_cell.grid(row=y, column=6, sticky='news') 

Replace your change_img so that there are no ifs, and everything is done via list lookup from the row index passed. Replace root.img*, root.load_img* and root.render_img* with lists.

Source Link
Reinderien
  • 71.2k
  • 5
  • 76
  • 257

If there's a list, make it a list

Do not represent RxCx variables as separate variables. Represent them as nested lists and it will greatly simplify your code. Consider grouping them by what makes them similar - column 0 (image_col), columns 1-5 (info_cols) and column 6 (instruction_col) as in the following example:

image_col = [ tk.Button( canv_1, image=root.render1, relief="raised", bg="light gray", command = lambda: change_img(y), ) for y in range(1, 6) ] for y, image_cell in enumerate(image_col, 1): image_cell.grid(row=y, column=0, sticky='news') instruction_col = [ tk.Text( canv_1, bg="white", wrap="word", font=("arial",15), width=20, height=10) ] for y, image_cell in enumerate(instruction_col , 1): image_cell.grid(row=y, column=6, sticky='news') 

Replace your change_img so that there are no ifs, and everything is done via list lookup from the row index passed. Replace root.img*, root.load_img* and root.render_img* with lists.