My buttons keep having white borders, how do I fix this?

33 Views Asked by At

This is my code. Whenever I click and hold on a button, the border is always white. Does anyone know why? This is also python 11.6.

class WelcomeScreen(tk.Frame):
    def __init__(self, master):
        super().__init__(master, bg="#3de053")
        self.pack()

        self.label_welcome = tk.Label(self, text="Hi, welcome to the BookBuddy!", bg="#3de053", font=("Arial", 14))
        self.label_welcome.pack(pady=20)

        self.tools = Tools()

        self.image = Image.open("Buttons/login.png")
        login_image = self.tools.resize(self.image, 100, 27)
        self.login_image_final = ImageTk.PhotoImage(login_image)
        self.login_button = tk.Button(self, image=self.login_image_final, bg="#3de053", bd=0, relief="flat", highlightthickness=0)
        self.login_button.pack(pady=10)

        # Bind both press and release events for the login button
        self.login_button.bind("<Button-1>", self.on_login_button_press)
        self.login_button.bind("<ButtonRelease-1>", self.on_login_button_release)

        self.image = Image.open("Buttons/signup.png")
        signup_image = self.tools.resize(self.image, 100, 30)
        self.signup_image_final = ImageTk.PhotoImage(signup_image)
        self.signup_button = tk.Button(self, image=self.signup_image_final, bg="#3de053", bd=0, relief="flat", highlightthickness=0)
        self.signup_button.pack(pady=10)

        # Bind both press and release events for the signup button
        self.signup_button.bind("<Button-1>", self.on_signup_button_press)
        self.signup_button.bind("<ButtonRelease-1>", self.on_signup_button_release)

    def on_login_button_press(self, event):
        self.login_button.configure(bg="#3de053",bd=0,relief="flat",highlightthickness=0)  # Set the background color when pressed
        self.login_button.pack(pady=10)

    def on_login_button_release(self, event):
        self.login_button.configure(bg="#4caf50",bd=0,relief="flat",highlightthickness=0)  # Set the background color when released
        self.login_button.pack(pady=10)
        self.master.show_login_screen()

    def on_signup_button_press(self, event):
        self.signup_button.configure(bg="#3de053",bd=0,relief="flat",highlightthickness=0)  # Set the background color when pressed
        self.signup_button.pack(pady=10)

    def on_signup_button_release(self, event):
        self.signup_button.configure(bg="#4caf50",bd=0,relief="flat",highlightthickness=0)  # Set the background color when released
        self.signup_button.pack(pady=10)
        self.master.show_signup_screen()

Attached is an image of what is happening. It happens for both login and signup. https://i.stack.imgur.com/TqXzS.png

I attempted to fix is by packing the buttons again and changing everything every time the press button is the border is always white!

1

There are 1 best solutions below

1
Tiles Hop Gaming On

the answer is..

self.login_button.configure(bg="#3de053", relief="flat", highlightthickness=0, highlightbackground="#3de053")

and thanks.