skip to Main Content

Here’s my Tkinter code:

Photoshop = Tkinter.Button(root, 
    text = 'Photoshop',
    fg = '#37d3ff',
    bg = '#001d26',
    bd =  10, 
    highlightthickness=4, 
    highlightcolor="#37d3ff", 
    highlightbackground="#37d3ff", 
    borderwidth=4)

However, after I grid my Button, the color of border doesn’t shows up. Instead, it used default grey.

5

Answers


  1. This works for me:

    import Tkinter as tk
    
    root = tk.Tk()
    
    Photoshop = tk.Button(root, text = 'Photoshop',
                          fg = '#37d3ff',
                          bg = '#001d26',
                          bd =  10, 
                          highlightthickness=4, 
                          highlightcolor="#37d3ff", 
                          highlightbackground="#37d3ff", 
                          borderwidth=4)
    Photoshop.pack()
    
    root.mainloop()
    

    enter image description here

    Login or Signup to reply.
  2. You may place the button inside its own frame like this:

    buttonborder = Tkinter.Frame(root,
                                 highlightbackground="#37d3ff",
                                 highlightcolor="#37d3ff",
                                 highlightthickness=4,
                                 bd=0)
    
    photoshop = Tkinter.Button(buttonborder, 
                               text='Photoshop',
                               fg='#37d3ff',
                               bg='#001d26')
    
    Login or Signup to reply.
  3. You can add your widget to a Frame and make the Frame’s highlight background to be the color you want for your widget’s border. CODE Example:

    import tkinter as tk
    
    root = tk.Tk()
    
    buttonborder = tk.Frame(root, highlightbackground="#37d3ff",
                                      highlightthickness=3, bd=0)
    photoshop = tk.Button(buttonborder, text='Photoshop', fg='#37d3ff')
    photoshop.pack()
    buttonborder.pack()
    
    root.mainloop()
    
    Login or Signup to reply.
  4. You can do it with LabelFrame() and relief.
    Works in windows.

    from tkinter import *
    
    App = Tk()
    
    Border = LabelFrame(App,
                        bd=5, #<- Borderwidth.
                        bg="blue", #<- Border color.
                        relief=FLAT)
    Border.pack(padx=10, pady=10)
    
    Btn1 = Button(Border, #<- in Border Widget.
                  text="Button", 
                  font="Arial 16 bold",
                  width=16,
                  bg="red",
                  fg="white",
                  relief=FLAT)
    Btn1.pack()
    
    App.mainloop()
    
    Login or Signup to reply.
  5. There is no perfect way to do this unfortunately, But you sure can hack around and place a tkinter Frame that is just a little bigger than the actual button to set them apart by using the frame as a coloured border, Something like this. Should work on Win and Mac or any other OS’s..
    (assuming you already know how to work with tkinter root window..)
    `borderFrame = Frame(root, bg="red(your desired colour of choice)")
    borderFrame.pack(padx=21, pady=21)

     button = Button(borderFrame, bg="blue",text="click me", relief='flat')
     button.pack(padx=20, pady=20)`
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search