I'm trying to create a login page in Tkinter with .pack(). I wold like to place the loginFrame at the center of the small window. And inside the loginFrame, the username section on top of the password section.
def main():
window = tk.Tk()
window.geometry("400x200")
window.title("PySploit")
window.resizable(False, False)
window.configure(background="#E1E5F2")
loginFrame = tk.Frame(window).pack(anchor="center")
usernameFrame = tk.Frame(loginFrame).pack(side=LEFT)
passwordFrame = tk.Frame(loginFrame).pack(side=LEFT)
tk.Label(usernameFrame, text="Username").pack(side=LEFT)
tk.Entry(usernameFrame, name="username").pack(side=LEFT)
tk.Label(passwordFrame, text="Password").pack(side=LEFT)
tk.Entry(passwordFrame, name="password").pack(side=LEFT)
window.mainloop()
return
if __name__ == "__main__":
main()
This is my wrong output:

For your requirement, you don't need
usernameFrameandpasswordFrame, justloginFrameis enough.You can put
loginFrameat the center of the window usingplace()instead and put those labels and buttons insideloginFrameusinggrid():