How to remove dashed lines from Tkinter Button in Python?

Viewed 317

I want to remove dashed lines from tkinter button I tried takefocus=False but it removed the access to get button focused via tab pressing.

enter image description here

How can i get rid of these lines when the user focuses In i want just the size of button should increase! I dont want these lines to cover the button.

from tkinter import *

class coloronfocus:
    def __init__(self,obj,size,color,color2):
        self.color2 = color2
        self.size = size
        self.color = color
        self.obj= obj
        self.obj.bind('<Enter>',self.enter)
        self.obj.bind('<Leave>',self.leave)
        self.obj.bind('<FocusIn>',self.enter)
        self.obj.bind('<FocusOut>',self.leave)
        self.INFO = (self.obj.place_info())
    def enter(self,event): # This method changes the size and color of object
        if not self.obj['state']=='disabled':
            self.obj.place(x=int(self.INFO['x'])-self.size,
                            y=int(self.INFO['y'])-self.size,
                            height=int(self.INFO['height'])+self.size*2,
                            width=int(self.INFO['width'])+self.size*2)
            self.obj.update()
            self.obj.config(bg=self.color,highlightthickness=0)
            self.obj.update()
    def leave(self,event): # This brings the real properties of object
        if not self.obj['state']=='disabled': 
            self.obj.place(x=int(self.INFO['x']),
                            y=int(self.INFO['y']),
                            height=int(self.INFO['height']),
                            width=int(self.INFO['width']))
            self.obj.update()
            self.obj.config(bg=self.color2,highlightthickness=0)
            self.obj.update()

root = Tk()

Button1 = Button(root,text="Button 1",bd=0,
                 bg='red',
                 fg='white',
                 highlightthickness=0,
                 activebackground='orange',
                 activeforeground='white',
                 command = lambda : print('Button 1 pressed'))
Button1.place(x=20,y=100,height=30,width=80)
coloronfocus(Button1,2,'orange','red')

Button2 = Button(root,text="Button 2",bd=0,
                 bg='red',
                 fg='white',
                 highlightthickness=0,
                 activebackground='orange',
                 activeforeground='white',
                 command=lambda : print('Button 2 pressed'))
Button2.place(x=110,y=100,height=30,width=80)
coloronfocus(Button2,2,'orange','red')

root.mainloop()
0 Answers
Related