1

I am new to using Tkinter, and I have been searching for a solution to remove the background color of the label widget for quite some time. Despite my efforts, I haven't been able to find a straightforward solution. I've tried various configurations and settings, but the label widget always seems to have a background color that I can't get rid of.

Note: code & screenshot below

import tkinter as tk
from tkinter import 
from PIL import Image, ImageTk
from tkinter import filedialog as fd

# Create the main root window

root = tk.Tk()
root.configure(bd=0)  # Remove the border of the main window

# Load and display the background image

bgImg = PhotoImage(file="w2.png")
width, height = 1000, 600  # Set desired width and height
bgImg = bgImg.subsample(bgImg.width() // width, bgImg.height() // height)
bgLabel = Label(root, image=bgImg)
bgLabel.place(x=0, y=0)

# Configure the main window

root.title("Arayüz Girdileri")  # Set the title of the window
root.geometry("1080x670")  # Set the initial size of the window
root.resizable(False, False)  # Disable window resizing

# Define a function for file selection

def selected_file():
filename = fd.askopenfilename(
title="Open a file",
initialdir='/',
filetypes=(("PNG Files", ".png"), ("All Files", ".\*"))
)

# Create a label for displaying map information

map_info = tk.Label(root, fg="white", bd=0, text="Harita Bilgileri", font=('Times New Roman', 20, 'bold'), relief="flat")
map_info.place(x=70, y=200)

# Create a button for opening a file dialog

open_button = tk.Button(root, bg="#F1F1F0", fg="black", bd=0, text="Open a File", command=selected_file)
open_button.place(x=250, y=200)

# Run the Tkinter main loop

root.mainloop()

I expect the background color to go, but it didn't get removed

Cow
  • 2,543
  • 4
  • 13
  • 25

0 Answers0