Python Forum
Tkinter grid columnspan being ignored
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter grid columnspan being ignored
#1
Hi so I am trying to create a table using grids and entrys in tkinter but my columnspan option is being ignored
def table(list, system):
	window = Toplevel(system)
	window.grid_columnconfigure((0, 1), weight=5, uniform="foo")
	window.grid_columnconfigure(2, weight=30, uniform="foo")
	height = len(list) + 2
	width = 3
	for i in range(height):
		for j in range(width):
			cel = Entry(window)
			
			cel.config(disabledbackground='white')
			cel.config(justify='center')
			cel.config(disabledforeground='black')
			if i == 0:
				if j == 0:
					cel.grid(row=i,column=j)
					cel.insert(0, "#")
				elif j == 1:
					cel.insert(0, "#")
					cel.grid(row=i,column=j)
				elif j == 2:
					cel.insert(0, "Materias")
					cel.grid(row=i,column=j, columnspan=30)
			cel.config(state='disabled')
That is the function to create it I am trying to make it so that the third column is longer but what it is outputing is the 3 columns and the third one has a lot of whitespace Can somebody point to what am I doing wrong?
Reply
#2
What happens when j > 2 or i > 0? When you columspan=30 it will only span columns that have something in them unless you also do a columnconfigure for all 30. I would suggest that you create all "normal" Entries, and then add in the columnspan=30 entries afterwords. For future reference, to eliminate the white space, comment out all unnecessary lines, and then uncomment them one by one to see where it is coming from.

from tkinter import *

def table(system):
    window = Toplevel(system)
    window.grid_columnconfigure((0, 1), weight=5, uniform="foo")
    window.grid_columnconfigure(2, weight=5, uniform="foo")
    height = 5
    width = 3
    for i in range(height):
        for j in range(width):
            cel = Entry(window)
            cel.config(disabledbackground='white')
            cel.config(justify='center')
            cel.config(disabledforeground='black')
            cel.grid(row=i,column=j)
            cel.insert(0, "#")
            cel.config(state='disabled')
root=Tk()
table(root)
root.mainloop() 
Reply
#3
I am sorry I don't get your explanation j is not going to be over 3 and what do you mean by all 30?
Reply
#4
Quote:j is not going to be over 3

in this one isolated instance, but i is greater than 0 and so those will not be gridded. Also, don't use list as a variable name as Python already uses list as a container type.

Quote:what do you mean by all 30?

"When you columnspan=30" Search for columnspan=30 in the code you posted.
Reply
#5
Sorry about the list thing I was translating code, but what I dont get is why the columnspan is not beign used. what I am trying to do is just make the third column have a span of 30(when j == 2)
Reply
#6
Do you really want an Entry that is 30 columns wide?
Reply
#7
Yes, the function puts a very long string in it's value so I need it to be long
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,388 May-25-2023, 07:37 PM
Last Post: deanhystad
  [Tkinter] Draw a grid of Tkinter Canvas Rectangles MrTim 5 7,774 May-09-2021, 01:48 PM
Last Post: joe_momma
  tkinter how to use whitespace with grid kiyoshi7 9 8,095 Feb-08-2018, 04:50 PM
Last Post: kiyoshi7
  Widget placement issues with tkinter grid thread 1 mgtheboss 2 4,319 Jan-09-2018, 03:59 PM
Last Post: SmokerX

Forum Jump:

User Panel Messages

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