Python Forum
Widget placement issues with tkinter grid thread 1 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Widget placement issues with tkinter grid thread 1 (/thread-7406.html)



Widget placement issues with tkinter grid thread 1 - mgtheboss - Jan-09-2018

Hi,

I am creating a gui with tkinter. I am facing some issues while attempting to place widgets on a grid. The issues are:
1. All three rows are showing up at the bottom. I want them vertically centered.
2. In the last of three rows, the button "a" is taking a lot more space than button "b" despite the fact that columnspan is 2 for both.

Here is the code.

from tkinter import *
from tkinter import ttk
root = Tk()
root.title("Unit-20180109")					  
frame1 = ttk.Frame(root, padding="10 10 10 10")
frame1.grid(column=0, row=0, sticky=(N, W, E, S))
frame1.columnconfigure(0, weight=1)
frame1.rowconfigure(0, weight=1)
notebook1 = ttk.Notebook(frame1, width="800", height="600")
screen1 = ttk.Frame(notebook1) 
notebook1.add(screen1, text="screen 1")
notebook1.grid()
screen1.grid_columnconfigure(0, weight=1)
screen1.grid_rowconfigure(0, weight=1)
combobox1var = StringVar()
combobox1=ttk.Combobox(screen1, textvariable=combobox1var, values=("Provide an input ...", "a", "b", "c", "d", "e", "f"), state="readonly" )
combobox1.current(0)
combobox1.grid(padx=10, row=3, column=0, rowspan=1, columnspan=4, sticky="new" )
entry1var=StringVar()
entry1=ttk.Entry(screen1, textvariable=entry1var)
entry1.grid(padx=10, row=4, column=0, rowspan=1, columnspan=4, sticky="new")
button1= ttk.Button(screen1, text="a")
button2= ttk.Button(screen1, text="b")
button1.grid(padx=10, row=5, column=0, rowspan=1, columnspan=2, sticky="new")
button2.grid(padx=10, row=5, column=2, rowspan=1, columnspan=2, sticky="new")
root.mainloop()
Here is the output at the moment.
[Image: nfIbq7X]

Version information: python 3.4.3, tkinter 8.6

I appreciate the cooperation of forum members.


RE: Widget placement issues with tkinter grid thread 1 - Barrowman - Jan-09-2018

Sorry but I can't help you with this, personally I would have left out almost all of the row and column configuring code and start by just testing as you add each frame, entry and button. I don't understand why you have added so much complication and find it hard to see what value there is in it.
from tkinter import *
from tkinter import ttk
root = Tk()
root.title("Unit-20180109")                   
frame1 = ttk.Frame(root, padding="10 10 10 10")
frame1.grid()#(column=0, row=0, sticky=(N, W, E, S))
#frame1.columnconfigure(0, weight=1)
#frame1.rowconfigure(0, weight=1)
notebook1 = ttk.Notebook(frame1, width="800", height="600")
screen1 = ttk.Frame(notebook1) 
notebook1.add(screen1, text="screen 1")
notebook1.grid()
screen1.grid() #_columnconfigure(0, weight=1)
#screen1.grid_rowconfigure(0, weight=1)
combobox1var = StringVar()
combobox1=ttk.Combobox(screen1, textvariable=combobox1var, values=("Provide an input ...", "a", "b", "c", "d", "e", "f"), state="readonly" )
combobox1.current(0)
combobox1.grid(padx=10, row=3, column=0, rowspan=1, columnspan=4, sticky="new" )
entry1var=StringVar()
entry1=ttk.Entry(screen1, textvariable=entry1var)
entry1.grid(padx=10, row=4, column=0) #, rowspan=1, columnspan=2, sticky="new")
button1= ttk.Button(screen1, text="a")
button2= ttk.Button(screen1, text="b")
button1.grid(padx=10, row=5, column=0) #, rowspan=1, columnspan=1, sticky="new")
button2.grid(padx=10, row=6, column=0) #, rowspan=1, columnspan=1, sticky="new")
root.mainloop()
I edited out a lot of what you put but don't know if it's nearer to what you seem to want.


RE: Widget placement issues with tkinter grid thread 1 - SmokerX - Jan-09-2018

I think you have row and column mixed up. I think screen1 is dictating grid size so rows are huge. Im not sure if youre mistaking screen1 for a root window. If so delete screen1. You can also use place instead of grid. I think there's a way to bring widgets to the foreground to attempt to wrangle the grid size with rowspan and columnspan. Look at what I did here with the bottom buttons grid position in the code. I toy with it to get an idea of what my grid size is doing.
from tkinter import *
from tkinter import ttk
root = Tk()
root.title("Unit-20180109")                   
frame1 = ttk.Frame(root, padding="10 10 10 10")
frame1.grid(column=0, row=0, sticky=(N, W, E, S))
frame1.columnconfigure(0, weight=1)
frame1.rowconfigure(0, weight=1)
notebook1 = ttk.Notebook(frame1, width="800", height="600")
screen1 = ttk.Frame(notebook1) 
notebook1.add(screen1, text="screen 1")
notebook1.grid()
screen1.grid_columnconfigure(0, weight=1)
screen1.grid_rowconfigure(0, weight=1)
combobox1var = StringVar()
combobox1=ttk.Combobox(screen1, textvariable=combobox1var, values=("Provide an input ...", "a", "b", "c", "d", "e", "f"), state="readonly" )
combobox1.current(0)
combobox1.grid(padx=10, row=3, column=0, rowspan=1, columnspan=4, sticky="new" )
entry1var=StringVar()
entry1=ttk.Entry(screen1, textvariable=entry1var)
entry1.grid(padx=10, row=4, column=0, rowspan=1, columnspan=4, sticky="new")
button1= ttk.Button(screen1, text="a")
button2= ttk.Button(screen1, text="b")
button1.grid(padx=10, row=5, column=0, rowspan=1, columnspan=2, sticky=W)
button2.grid(padx=10, row=5, column=0, rowspan=1, columnspan=2,)
button2.tag_raise(firstRect)
root.mainloop()