0

I am wondering how to set the max amount of columns in a tkinter grid so my text does not get pushed off screen and everything re adjusts to fit. I am going to want to set the max amount of columns to 6. I haven't found anything online about this so I hope people can help me. Also it would be helpful to know how to set the max amount of rows. Hope the community can help Here I am using 6 columns:

day0infol = Label(text=day0infoF)
day0infol.grid(column = 0,row = 2,padx = 20)

day1dayl = Label(text=day1dayF, font=customFont)
day1dayl.grid(column=1,row=0,padx=20)

day2dayl = Label(text=day2dayF, font=customFont)
day2dayl.grid(column = 2,row=0,padx=20)
day3dayl = Label(text=day3dayF, font=customFont)
day3dayl.grid(column = 3,row=0,padx=20)
day4dayl = Label(text=day4dayF, font=customFont)
day4dayl.grid(column = 4,row=0,padx=20)
day5dayl = Label(text=day5dayF, font=customFont)
day5dayl.grid(column = 5,row=0,padx=20)

I want to set six as the mximum columns or figure out how to do it another way. Hope you can help. Ignore the text variables

GCIreland
  • 145
  • 1
  • 16
  • 1
    You're the one that creates the columns If you don't want more than 6, don't put anything in the 7th column. – Bryan Oakley Nov 14 '21 at 16:49
  • If the text of those labels on the first 6 columns are very long, some labels will still be pushed out of viewable area if the width of the window cannot show all the text, no matter how many columns you have used. – acw1668 Nov 15 '21 at 01:52

1 Answers1

1

max amount of columns in a tkinter grid so my text does not get pushed off screen and everything re adjusts to fit.

How would a maximum of columns avoid that? A column can be 1000 or more pixel large in x and y direction.

The easiest way to go,since you dosent seem to create your Label in a function and dosent use a master parameter, should be:

root=tk.Tk()
root.grid_propagate(0)

The grid_propagate(0) command will instruct your window to ignore the requested width and height that your the children/widgets it contains want to claim.


Another approach could be to either create your Labels in a function and compare your if root.grid_info() has reached the max number of columns.

But why dont you use the tk.Text() widget anyway? Or even the tk.Scrolledtext() ?

Since you seem a beginner, please take a look at this post.

Thingamabobs
  • 7,274
  • 5
  • 21
  • 54