Python Forum
set button background with image of window background
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
set button background with image of window background
#1
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) 
see the attached file...it 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:
from tkinter import *
from PIL import Image, ImageTk

root = Tk()
root.title("Title")
root.geometry("400x400")
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()
Reply


Messages In This Thread
set button background with image of window background - by gray - Oct-12-2017, 07:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 529 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Transparent window background, but not text on it muzicman0 7 2,887 Feb-02-2024, 01:28 AM
Last Post: Joically
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,861 May-25-2023, 07:37 PM
Last Post: deanhystad
  My Background Image Is Not Appearing (Python Tkinter) HailyMary 2 4,334 Mar-14-2023, 06:13 PM
Last Post: deanhystad
  [Tkinter] Background inactivity timer when tkinter window is not active DBox 4 2,934 Apr-16-2022, 04:04 PM
Last Post: DBox
  [Tkinter] Clicking on the button crashes the TK window ODOshmockenberg 1 2,252 Mar-10-2022, 05:18 PM
Last Post: deanhystad
  [Tkinter] Not able to get image as background in a Toplevel window finndude 4 3,928 Jan-07-2022, 10:10 PM
Last Post: finndude
  [Tkinter] Why does the image for the button not appear? finndude 4 2,112 Oct-21-2021, 06:41 PM
Last Post: deanhystad
  [Tkinter] image inside button rwahdan 4 7,108 Jul-12-2021, 08:49 PM
Last Post: deanhystad
  tkinter showing image in button rwahdan 3 5,649 Jun-16-2021, 06:08 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020