Home > OS >  tkinter Entry not spanning columns
tkinter Entry not spanning columns

Time:10-18

this code currently produces:

enter image description here and enter image description here

I want the Username to start in aligned with First name and password and finish at last name and confirm two columns spans.

as you can see the Username entry only spans one column even thouh columnspan is set to 2. I need any solutions to fix this. Thanks

from tkinter import *

Master = ()
Master.attributes("-fullscreen", True)

Page = Frame(Master)
Page.place(relx = 0.5, rely = 0.5, anchor = "center")

FirstnameEntry = Entry(Page); FirstnameEntry.insert(0, "First name"); FirstnameEntry.grid(row = 0, column = 0)
FirstnameEntry.bind("<FocusIn>", lambda event: FirstnameEntry.get() == "First name" and FirstnameEntry.delete(0, END))
FirstnameEntry.bind("<FocusOut>", lambda event: FirstnameEntry.get() == "" and FirstnameEntry.insert(0, "First name"))

LastnameEntry = Entry(Page); LastnameEntry.insert(0, "Last name"); LastnameEntry.grid(row = 0, column = 1)
LastnameEntry.bind("<FocusIn>", lambda event: LastnameEntry.get() == "Last name" and LastnameEntry.delete(0, END))
LastnameEntry.bind("<FocusOut>", lambda event: LastnameEntry.get() == "" and LastnameEntry.insert(0, "Last name"))

UsernameEntry = Entry(Page); UsernameEntry.insert(0, "Username"); UsernameEntry.grid(row = 1, column = 0, columspan = 2)
UsernameEntry.bind("<FocusIn>", lambda event: UsernameEntry.get() == "Username" and UsernameEntry.delete(0, END))
UsernameEntry.bind("<FocusOut>", lambda event: UsernameEntry.get() == "" and UsernameEntry.insert(0, "Username"))

PasswordEntry = Entry(Page); PasswordEntry.insert(0, "Password"); PasswordEntry.grid(row = 2, column = 0)
PasswordEntry.bind("<FocusIn>", lambda event: PasswordEntry.get() == "Password" and PasswordEntry.delete(0, END))
PasswordEntry.bind("<FocusOut>", lambda event: PasswordEntry.get() == "" and PasswordEntry.insert(0, "Password"))

ConfirmEntry = Entry(Page); ConfirmEntry.insert(0, "Confirm"); ConfirmEntry.grid(row = 2, column = 1)
ConfirmEntry.bind("<FocusIn>", lambda event: ConfirmEntry.get() == "Confirm" and ConfirmEntry.delete(0, END))
ConfirmEntry.bind("<FocusOut>", lambda event: ConfirmEntry.get() == "" and ConfirmEntry.insert(0, "Confirm"))

Master.mainloop()

CodePudding user response:

Just add the sticky = "we" modifier

in the code:

.grid(row = 1, column = 0, columnspan = 2, sticky = "we")

CodePudding user response:

In line 3. You are missing widget.

Change this:

Master = ()

to:

Master = Tk()

And in line 17 followde by @Alex Jando.

Result:

enter image description here

  • Related