I am trying to design a screen in Python (Tkinter) and after researching the issue completely, I was not able to find a way to center both the Label and Entry box on the screen in the row that I would like. To be clear, I would not like it in the center of the screen, but rather in the center of the row I have selected.
I have tried some methods of .pack() and using a grid to do it but nothing seems to do what I would like.
I set the root like this:
root = tk.Tk()
I set the GUI width and height like this:
screen_width = str(root.winfo_screenwidth())
screen_height = str(root.winfo_screenheight())
root.geometry(screen_width + "x" + screen_height)
And I set the positions of the labels and their entry boxes like this:
fName = tk.Label(root, text="First Name")
fName.grid(row=0)
lName = tk.Label(root, text="Last Name")
lName.grid(row=1)
ageLabel = tk.Label(root, text="Age")
ageLabel.grid(row=2)
correctedLabel = tk.Label(root, text="Is your vision, or corrected to, 20/20? (Y/N)")
correctedLabel.grid(row=3)
genderLabel = tk.Label(root, text="Gender")
genderLabel.grid(row=4)
e1 = tk.Entry(root)
e2 = tk.Entry(root)
e3 = tk.Entry(root)
e4 = tk.Entry(root)
e5 = tk.Entry(root)
root.winfo_toplevel().title("Information Collection")
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
e3.grid(row=2, column=1)
e4.grid(row=3, column=1)
e5.grid(row=4, column=1)
With the current code I have, It will take the screen width and height from Tkinter and will resize the window to the screen size. Also using this code someone would see that there are 4 labels, and their corresponding entry boxes, and I would like to move each group of label and its entry to the center of its row. I would appreciate any help I could get on this.