I've attached an image below as well as my code and you can see that there's some space between the password label and the generate password button. I've tried all sorts of sizes and positions, but nothing seems to work. I'd appreciate any help. The image of my program showing the gap
from tkinter import *
window = Tk()
window.title("Password Manager")
window.config(padx=50, pady=50)
canvas = Canvas(width=200, height=200)
logo_img = PhotoImage(file="logo.png")
canvas.create_image(100, 100, image=logo_img)
canvas.grid(column=1, row=0)
website_label = Label(text="Website:")
website_label.grid(column=0, row=1)
email_label = Label(text="Email/Username:")
email_label.grid(column=0, row=2)
password_label = Label(text="Password:")
password_label.grid(column=0, row=3)
website_entry = Entry(width=35)
website_entry.grid(column=1, row=1, columnspan=2)
email_entry = Entry(width=35)
email_entry.grid(column=1, row=2, columnspan=2)
password_entry = Entry(width=17)
password_entry.grid(column=1, row=3)
generate_password_button = Button(text="Generate Password")
generate_password_button.grid(column=2, row=3)
add_button = Button(text="Add", width=30)
add_button.grid(column=1, row=4, columnspan=2)
window.mainloop()
If you mean the space between the password entry box password_entry
and the generate_password_button
, then it is caused by the size of the canvas. Simply put the canvas at column 0 with columnspan=3
will fix it. For better alignment, add sticky="ew"
to .grid(...)
on those entry boxes and buttons.
Below is the modified code:
from tkinter import *
window = Tk()
window.title("Password Manager")
window.config(padx=50, pady=50)
canvas = Canvas(width=200, height=200)
logo_img = PhotoImage(file="logo.png")
canvas.create_image(100, 100, image=logo_img)
canvas.grid(column=0, row=0, columnspan=3) # put at column 0 with columnspan=3
website_label = Label(text="Website:")
website_label.grid(column=0, row=1)
email_label = Label(text="Email/Username:")
email_label.grid(column=0, row=2)
password_label = Label(text="Password:")
password_label.grid(column=0, row=3)
website_entry = Entry(width=35)
website_entry.grid(column=1, row=1, columnspan=2, sticky="ew") # added sticky="ew"
email_entry = Entry(width=35)
email_entry.grid(column=1, row=2, columnspan=2, sticky="ew")
password_entry = Entry(width=17)
password_entry.grid(column=1, row=3, sticky="ew")
generate_password_button = Button(text="Generate Password")
generate_password_button.grid(column=2, row=3, sticky="ew")
add_button = Button(text="Add", width=30)
add_button.grid(column=1, row=4, columnspan=2, sticky="ew")
window.mainloop()
Result: