1

The checkboxes I use in my program have a large gap between checkbox 2 and 3 when the program is run.

I figured out that this is caused by my entry widget as when I commented it out the gap between checkboxes 2 and 3 disappeared. I am unsure how to get rid of this invisible gap since the checkboxes and the entry widget are in different rows, therefore, it leads me to believe that there should be no interference between the two widgets.

from tkinter import *
import tkinter as tk

master = tk.Tk()

tk.Label(master, text="First Name").grid(row=0)
Entry(master).grid(row=0, column=1)

var1 = IntVar()
var2 = IntVar()
var3 = IntVar()

Checkbutton(master, text="1", variable=var1).grid(row=2,column=0, sticky=W)
Checkbutton(master, text="2", variable=var2).grid(row=2, column=1, sticky=W)
Checkbutton(master, text="3", variable=var3).grid(row=2, column=2, sticky=W)

Button(master,text="QUIT",command=master.quit, fg="red").grid(row=3,column=1)

master.mainloop()
Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80
Jack
  • 44
  • 6
  • 2
    Yes, it's always the widest widget that sets the width of the entire column. One easy fix is to have the Entry span 2 or 3 columns by adding the argument `columnspan=3`. You'll probably want to do the same for the Button. – Novel Oct 28 '20 at 03:32
  • I would prefer putting those checkbuttons in a frame so that they can be laid out independently. – acw1668 Oct 28 '20 at 03:58

1 Answers1

2

You can place your buttons in a frame that spans the width of the app. The Entry can be adjusted to also span several columns.

Maybe like this:

enter image description here

import tkinter as tk

master = tk.Tk()

tk.Label(master, text="First Name").grid(row=0)
tk.Entry(master).grid(row=0, column=1, columnspan=2)

var1 = tk.IntVar()
var2 = tk.IntVar()
var3 = tk.IntVar()


checkbtns = tk.Frame(master)
tk.Checkbutton(checkbtns, text="1", variable=var1, padx=10).pack(side=tk.LEFT, anchor=tk.W)
tk.Checkbutton(checkbtns, text="2", variable=var2, padx=10).pack(side=tk.LEFT, anchor=tk.W)
tk.Checkbutton(checkbtns, text="3", variable=var3, padx=10).pack(side=tk.LEFT, anchor=tk.W)
checkbtns.grid(row=2, column=0, columnspan=3)

tk.Button(master, text="QUIT", command=master.destroy, fg="red").grid(row=3, column=0, columnspan=3)

master.mainloop()
Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80