0

in the following GUI code, there are six pairs of labels and entry boxes over grid columns from 0 to 5. However, when running the code, they are not evenly spaced. Could anyone make a suggestion to fix this problem? Thank you.

from tkinter import *
from tkinter import ttk

def main ():

    root = Tk()
    root.geometry("1600x800+0+0")

    root.configure(bg='Dodgerblue4')
    root.grid_rowconfigure(0 , weight=1)
    root.grid_columnconfigure(0 , weight=1)
    master = Frame(root , bg='Dodgerblue4')
    master.pack()
    #master.grid(row=0 , column=0 , sticky="nsew")



    # ---------------------------------Eye Model-------------------------------------------------------------------------

    label_top = Label(master , text="Welcome to the Design Page" , font=('' , '15' , '') ,
                      bg='Dodgerblue4' , pady=15 , fg='white')
    label_top.grid(row=0  , column=2)

    # -------------------------------------------------------------------------------------------------------------------
    label_corasph = Label(master , text='Cornea Asphericity (Q)' , fg='white' , bg='Dodgerblue4', font=('' , '12' , '')).grid(row= 2 ,
                                                                                                       column=0, columnspan=1)
    var_corasph = DoubleVar()
    entry_corasph = Entry(master , justify=CENTER , textvariable=var_corasph , state='disabled', font=('' , '12' , ''), width=10)
    entry_corasph.grid(row= 3 , column=0 , ipady=5)
    var_corasph.set(-0.25)
    # -----------------------------------------------------------------------------------------------------------------------
    label_corrad = Label(master , text='Cornea Radius (mm)' , fg='white' , bg='Dodgerblue4', font=('' , '12' , '')).grid(row= 2 ,
                                                                                                  column= 1, columnspan=1)
    var_corrad = DoubleVar()
    entry_corrad = Entry(master , justify=CENTER , textvariable=var_corrad , state='disabled', font=('' , '12' , ''), width=10)
    entry_corrad.grid(row= 3 , column= 1 , ipady=5)
    var_corrad.set(7.50)
    # ------------------------------------------------------------------------------------------------------------------------
    label_sclasph = Label(master , text='Scleral Asphericity (Q)' , fg='white' , bg='Dodgerblue4', font=('' , '12' , '')).grid(row= 2 ,
                                                                                                        column= 2, columnspan=1)
    var_sclasph = DoubleVar()
    entry_sclasph = Entry(master , justify=CENTER , textvariable=var_sclasph, state='disabled', font=('' , '12' , ''), width=10)
    entry_sclasph.grid(row= 3 , column= 2 , ipady=5)
    var_sclasph.set(-0.05)
    # ------------------------------------------------------------------------------------------------------------------------
    label_sclrad = Label(master , text='Scleral Radius (mm)' , fg='white' , bg='Dodgerblue4', font=('' , '12' , '')).grid(row= 2 ,
                                                                                                   column= 3, columnspan=1)
    var_sclrad = DoubleVar()
    entry_sclrad = Entry(master , justify=CENTER , textvariable=var_sclrad, state='disabled', font=('' , '12' , ''), width=10)
    entry_sclrad.grid(row= 3 , column= 3 , ipady=5)
    var_sclrad.set(11.20)
    # ------------------------------------------------------------------------------------------------------------------------
    label_limbal = Label(master , text='Limbal Semi-Diameter (mm)' , fg='white' , bg='Dodgerblue4', font=('' , '12' , '')).grid(row= 2 ,
                                                                                                         column= 4, columnspan=1)
    var_limbal = DoubleVar()
    entry_limbal = Entry(master , justify=CENTER , textvariable=var_limbal, state='disabled', font=('' , '12' , ''), width=10)
    entry_limbal.grid(row= 3 , column= 4 , ipady=5)
    var_limbal.set(6.00)
    # ------------------------------------------------------------------------------------------------------------------------
    label_clearance = Label(master , text='Clearance (mm)' , fg='white' , bg='Dodgerblue4', font=('' , '12' , '')).grid(row= 2 ,
                                                                                                 column= 5, columnspan=1)
    var_clearance = DoubleVar()
    entry_clearance = Entry(master , justify=CENTER , textvariable=var_clearance, state='disabled', font=('' , '12' , ''), width=10)
    entry_clearance.grid(row= 3 , column= 5 , ipady=5)
    var_clearance.set(0.30)

    root.mainloop()

    return


if __name__ == '__main__':
    main()
Novel
  • 13,406
  • 2
  • 25
  • 41
Payman Rajai
  • 47
  • 1
  • 7

1 Answers1

0

It's your title Label that is screwing up the spacing. Change the layout for the title label to this:

label_top.grid(row=0, column=0, columnspan=6)
Novel
  • 13,406
  • 2
  • 25
  • 41