I’m trying to create an app for work, but I’m new to Tkinter. I want the company’s logo to show up in the top left corner. However, all I can get to show up is a blank grey box. It is worth noting that this is an image with a transparent background, however, I was able to get that to show up before when my code was not organized into classes. The image size should also not be a problem. I resized it specifically to fit in the frame that I am using.
Blank grey box
I’ve tried this several different ways: using a Canvas widget, and using a Label widget. However, neither of these work. When I use the Canvas widget, all that shows up is a blank grey box. I get nothing at all out of the label widget.
My code is below. The exact same code was working when the program wasn’t organized into classes. But, I decided that an incomprehensible stream of code isn’t the best when building out an app.
I only pasted the main class and the logo class here. There are others, but they are not relevant to what I am currently doing.
from tkinter import *
from tkinter import ttk
from PIL import ImageTk,Image
class MainApp(Tk):
def __init__(self, title, size):
super().__init__()
#Main Setup
self.title(title)
self.geometry(f"{size[0]}x{size[1]}")
self.minsize(size[0],size[1])
#Main Frames
self.logo = Logo(self)
self.left = Left(self)
self.right = Right(self)
self.content = Content(self)
self.columnconfigure(1, weight=6)
self.columnconfigure(0, weight=0)
self.columnconfigure(2, weight=0)
self.rowconfigure(1, weight=6)
self.rowconfigure(0, weight=0)
self.mainloop()
class Logo(ttk.Frame):
def __init__(self, parent):
super().__init__(parent)
self = ttk.Frame(parent, borderwidth=5, relief="ridge", width = 1000, height = 50)
unipart = Canvas(self, width = 171, height = 50)
self.grid(row=0,column=0, columnspan=3, rowspan=1, sticky=("N", "S", 'E', 'W'))
image = Image.open("Py GUI\unipart-logo.png")
unipart = ImageTk.PhotoImage(image)
self.label=Label()
self.label['image'] = unipart
self.label.grid(column=0, row=0, columnspan=1, rowspan=1, sticky=("S"))
# unipart = ttk.Label(self)
# img = ImageTk.PhotoImage(file='Py GUI\unipart-logo.png')
# unipart['image'] = img
# unipart.grid(column=0, row=0, columnspan=1, rowspan=1)
Eshaan Agarwal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.