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 Widget Attribute and Method Quick Reference zunebuggy 3 786 Oct-15-2023, 05:49 PM
Last Post: zunebuggy
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,369 May-25-2023, 07:37 PM
Last Post: deanhystad
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 4,664 Jun-26-2022, 06:26 PM
Last Post: menator01
  [Tkinter] scheduling and timining issues using mqtt and tkinter kiko4590 2 1,781 Apr-11-2022, 08:23 AM
Last Post: kiko4590
  Tkinter Exit Code based on Entry Widget Nu2Python 6 2,871 Oct-21-2021, 03:01 PM
Last Post: Nu2Python
  [Tkinter] Draw a grid of Tkinter Canvas Rectangles MrTim 5 7,757 May-09-2021, 01:48 PM
Last Post: joe_momma
  tkinter text widget word wrap position chrisdb 6 7,442 Mar-18-2021, 03:55 PM
Last Post: chrisdb
  Grid Placement In Python finndude 2 2,107 Mar-06-2021, 05:44 PM
Last Post: deanhystad
  Tkinter - How can I extend a label widget? TurboC 2 2,730 Oct-13-2020, 12:15 PM
Last Post: zazas321
  changing tkinter label from thread nanok66 3 7,210 Jun-07-2020, 01:37 AM
Last Post: nanok66

Forum Jump:

User Panel Messages

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