Home > Back-end >  How to set max amount of columns in tkinter grid?
How to set max amount of columns in tkinter grid?

Time:11-16

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

CodePudding user response:

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.

  • Related