-4

I wanted the button and password input to be right next to each other without a gap, but I ran into this problem and there was a gap between them. I tried to remove the space between this input and the button with padx, pady but I didn't succeed. I need your help to make these two side by side and

This is my code :

window = Tk()
window.title("Password Manager")
window.config(padx=20, pady=20, bg="white")

canvas= Canvas(width=200, height=200 , bg="white", highlightthickness=0)
canvas.config(bg="white")
logo_img = PhotoImage(file="logo.png")
canvas.create_image(100, 100, image=logo_img)
canvas.grid(row=0, column=1)


website_label = Label(text="Website:", bg="white",font=("Arial", 10, "bold"))
website_label.grid(row=1, column=0)
website_label.config(bg="white")

website_entry = Entry(width=35,highlightthickness=2, bd=2)
website_entry.grid(row=1, column=1, columnspan=2)
website_entry.focus()

email_label = Label(text="Email/Username:", bg="white",font=("Arial", 10, "bold"))
email_label.grid(row=2, column=0)
email_label.config(bg="white")

email_entry = Entry(width=35,highlightthickness=2, bd=2)
email_entry.grid(row=2, column=1, columnspan=2)
email_entry.insert(0,"[email protected]")

password_label = Label(text="Password:", bg="white",font=("Arial", 10, "bold"))
password_label.grid(row=3, column=0)
password_label.config(bg="white")

password_entry = Entry(width=21,highlightthickness=2, bd=2)
password_entry.grid(row=3, column=1 )

generate_button = Button(text="Generate Password", width=17, bg="white", font=("Arial", 8), command=generate_password)
generate_button.grid(row=3, column=2)

add_button = Button(text="Add", width=36, bg="white", font=("Arial", 8, "bold"),command=save)
add_button.grid(row=4, column=1, columnspan=2)


window.mainloop()
8
  • 2
    How can we help without a minimal reproducible example? Commented Apr 30 at 16:14
  • As @acw1668 said, try to aim for a minimal reproducible sample. We want to help you, but we can only do that if we have some idea of what we're actually working with. Commented Apr 30 at 16:45
  • without your code we have no idea what is your problem. Different code may need different solution. Commented Apr 30 at 17:14
  • @acw1668 and the other . You are right .I forgot to put the code. I fixed it Commented May 2 at 9:16
  • 1
    Please update your code so that we can run it. The imports and the function save are missing. Ideally, you should condense your code into a small minimal reproducible example for Stackoverflow. Commented May 7 at 12:12

1 Answer 1

0

The simple way is to added sticky="ew" to .grid(...) on those entries and buttons. Also put the canvas at column 0 with columnspan=3:

from tkinter import *

save = generate_password = None

window = Tk()
window.title("Password Manager")
window.config(padx=20, pady=20, bg="white")

canvas= Canvas(width=200, height=200 , bg="white", highlightthickness=0)
canvas.config(bg="white")
logo_img = PhotoImage(file="logo.png")
canvas.create_image(100, 100, image=logo_img)
canvas.grid(row=0, column=0, columnspan=3) # put column 0 with columnspan=3


website_label = Label(text="Website:", bg="white",font=("Arial", 10, "bold"))
website_label.grid(row=1, column=0)
website_label.config(bg="white")

website_entry = Entry(width=35,highlightthickness=2, bd=2)
website_entry.grid(row=1, column=1, columnspan=2, sticky="ew") # added sticky
website_entry.focus()

email_label = Label(text="Email/Username:", bg="white",font=("Arial", 10, "bold"))
email_label.grid(row=2, column=0)
email_label.config(bg="white")

email_entry = Entry(width=35,highlightthickness=2, bd=2)
email_entry.grid(row=2, column=1, columnspan=2, sticky="ew") # added sticky
email_entry.insert(0,"[email protected]")

password_label = Label(text="Password:", bg="white",font=("Arial", 10, "bold"))
password_label.grid(row=3, column=0)
password_label.config(bg="white")

password_entry = Entry(width=21,highlightthickness=2, bd=2)
password_entry.grid(row=3, column=1, sticky="ew") # added sticky

generate_button = Button(text="Generate Password", width=17, bg="white", font=("Arial", 8), command=generate_password)
generate_button.grid(row=3, column=2, sticky="ew") # added sticky

add_button = Button(text="Add", width=36, bg="white", font=("Arial", 8, "bold"),command=save)
add_button.grid(row=4, column=1, columnspan=2, sticky="ew") # added sticky


window.mainloop()

Result:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.