I want to set a png as the background image in a custokinter UI I have this code
import customtkinter
import random
from PIL import Image
import PIL
customtkinter.set_appearance_mode("light")
# Create a list to track the names that have already been chosen
chosen_names = []
def button_callback():
# Create a list of names
names = ["Alice", "Bob", "Carol", "Dave", "Eve"]
# Randomly select a name from the list
name = random.choice(names)
# Check if the name has already been chosen
while name in chosen_names:
name = random.choice(names)
# Add the name to the list of chosen names
chosen_names.append(name)
# Get the label
#label = app.winfo_children()[0]
# Update the label text
label.configure(text=name)
label.grid_remove()
# Check if all the values in the list have been selected
if len(chosen_names) == len(names):
chosen_names.clear()
label.configure(text="")
app = customtkinter.CTk()
image = PIL.Image.open("Imagen.png")
background_image = customtkinter.CTkImage(image)
app.title("app")
app.iconbitmap('isologo.ico')
app.geometry("500x500")
# Create a label
label = customtkinter.CTkLabel(app)
label.pack(padx=0, pady=0)
label.configure(text="")
button = customtkinter.CTkButton(app, text="Selector Nombre", command=button_callback)
button.pack(ipadx=20, ipady=20,padx=20, pady=50)
app.mainloop()
how would i set
image = PIL.Image.open("Imagen.png")
as the background? The background can be static and doesn't have to change size, but if it is a bit responsive, it will be much better.
You can use this example how to set custom bg image + dynamic resizing:
Creates this window with "Python background":