#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2017
    Posts
    31
    Rep Power
    1

    Question how to set button background with window background


    hello freinds
    i have put an image (self.image) on my window background 
     now,
    i need to put another image(mi_but1) on this window..
    my problem:
    image mi_but1 is put on window with a gray square behind it(a gray square between image mi_but1 and window's background) 
    the final gui doesnt look nice
    i don't want this gray background...
    what should I do? how can i remove this gray square behind the button(button background)? OR how can i put the image of window background(self.image) in behind of the button (button background)
    my code:
    Code:
    from tkinter import *
    from PIL import Image, ImageTk
    
    root = Tk()
    root.title("Title")
    root.geometry("600x600")
    root.configure(background="black")
    
    class Example(Frame):
        def __init__(self, master, *pargs):
            Frame.__init__(self, master, *pargs)
    
            self.image = Image.open("/home/pi/Desktop/images/background/image.png")
            self.img_copy= self.image.copy()
    
    
            self.background_image = ImageTk.PhotoImage(self.image)
    
            self.background = Label(self, image=self.background_image)
            self.background.pack(fill=BOTH, expand=YES)
            self.background.bind('<Configure>', self._resize_image)
    
            mi_but1=PhotoImage(file="/home/pi/Downloads/images/buttons/starlarg.png")
            button2 = Button(self.background, text='button2',image=mi_but1)
            button2.image=mi_but1
            button2.pack(side='top')
    
        def _resize_image(self,event):
    
            new_width = event.width
            new_height = event.height
    
            self.image = self.img_copy.resize((new_width, new_height))
    
            self.background_image = ImageTk.PhotoImage(self.image)
            self.background.configure(image =  self.background_image)
    
    e = Example(root)
    e.pack(fill=BOTH, expand=YES)
    root.mainloop()
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,861
    Rep Power
    509
    button2 = Button(self.background, text='button2',image=mi_but1, borderwidth = 1)

    Seems like there's a minimum of 1 pixel borderwidth. (bd = -8 looks like bd=1)
    You can also try the relief option, which isn't likely to help.
    highlightbackground, background, activebackground can change the color from gray.
    Investigating transparency: https://stackoverflow.com/questions/...tkinter-window
    If your image is simple you can draw it on a canvas and attach buttons to figures.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2017
    Posts
    31
    Rep Power
    1
    Originally Posted by b49P23TIvg
    button2 = Button(self.background, text='button2',image=mi_but1, borderwidth = 1)

    Seems like there's a minimum of 1 pixel borderwidth. (bd = -8 looks like bd=1)
    You can also try the relief option, which isn't likely to help.
    highlightbackground, background, activebackground can change the color from gray.
    Investigating transparency: https://stackoverflow.com/questions/...tkinter-window
    If your image is simple you can draw it on a canvas and attach buttons to figures.
    i used bd, relief, bg, highlightthickness,....but it wasn't usable..
    i used the canvas...it was usable...the square region about my image is not visible but there is this region yet...so when i click on region near my image,"bind" function on image acts
  6. #4
  7. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,861
    Rep Power
    509
    As I recall it's possible to have the canvas highlight included objects when the mousy pointer is near them.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo