1

I am constructing a simple python program to make a window using tkinter with a background stored as an image on the computer.

  • I first made a full-sized window and displayed it.

  • I put a canvas on this window

  • I then used the photoimage class and used my png image. I then put this on the label.

  • At this point when I ran the code it worked perfectly.

  • I tried to add a button on top the label and what happens now is that the label with the pictures shrinks and the picture is barely visible around the button.

Here is my code:

from tkinter import *
import pyautogui as pag


def act():
    print("Hey")
    ##action here
root = Tk()

winWidth, winHeight = pag.size()

root.state("zoomed")

canvas = Canvas(root, width=winWidth, height=winHeight, bg="white")
canvas.pack()
canvas.pack_propagate(0)

bgClass = PhotoImage(master=root, file="backg.png")

background = Label(canvas, image=bgClass, width=winWidth, height=winHeight)
background.pack()

b = Button(background, text="Click me", command=act)
b.pack()


root.mainloop()

I have tried using pack_propagate() to stop the label from shrinking, but it does not work.

Does anyone know how to stop the picture from shrinking?

Thanks

Harman Punchi
  • 85
  • 2
  • 9

1 Answers1

0

I think this will work

bgclass=bgclass.resize((700,700), Image.ANTIALIAS)
background = Label(canvas, image=bgClass)
background.pack()

Here I have resized image to 700x700 you can change according to your requirement.

Saksham Kushwaha
  • 274
  • 1
  • 18