Python Forum
Widget placement issues with tkinter grid thread 1
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Widget placement issues with tkinter grid thread 1
#1
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.
Reply
#2
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.
Reply
#3
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Draw a grid of Tkinter Canvas Rectangles MrTim 5 331 May-09-2021, 01:48 PM
Last Post: joe_momma
  tkinter text widget word wrap position chrisdb 6 1,195 Mar-18-2021, 03:55 PM
Last Post: chrisdb
  Grid Placement In Python finndude 2 714 Mar-06-2021, 05:44 PM
Last Post: deanhystad
  Tkinter - How can I extend a label widget? TurboC 2 612 Oct-13-2020, 12:15 PM
Last Post: zazas321
  changing tkinter label from thread nanok66 3 1,708 Jun-07-2020, 01:37 AM
Last Post: nanok66
  Tkinter - Issues with "iconbitmap" method aquerci 3 1,837 May-21-2020, 09:46 AM
Last Post: aquerci
  [Tkinter] Tkinter custom widget styling and creating custom theme karolp 6 1,807 May-06-2020, 06:11 PM
Last Post: karolp
  Tkinter calendar widget scratchmyhead 4 1,627 May-03-2020, 07:01 PM
Last Post: scratchmyhead
  How to retreive the grid location of an Entry widget kenwatts275 7 1,034 Apr-24-2020, 11:39 PM
Last Post: Larz60+
  [PyGUI] Python 3.8.1 Tkinter Widget stete change sasiap 4 840 Feb-14-2020, 10:38 AM
Last Post: sasiap

Forum Jump:

User Panel Messages

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