Click here to Skip to main content
15,911,035 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hello, coding guys,

As I mentioned in the title, my code does not work. Here's the source below:

main.py
import tkinter as tk
from tkinter import *

def about():
	aboutroot = Toplevel(root)
	aboutroot.title("About BeatCinema")
	aboutroot.geometry("235x198")
	aboutroot.iconphoto(False, PhotoImage(file="beatcinema.png"))
	aboutroot.resizable(False, False)
	aboutlogo = Label(aboutroot, image=PhotoImage(file="beatcinema.png"))
	aboutlogo.place(relx=0.5, rely=0.0, anchor=CENTER)

root = Tk()
root.title("BeatCinema")
root.geometry("450x225")
root.iconphoto(False, PhotoImage(file="beatcinema.png"))
root.resizable(False, False)
greet = Label(root, text="Welcome to BeatCinema", font=("sans-serif", 16))
greet.pack()
menu = Menu(root)
filemenu = Menu(menu, tearoff=0)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="About", command=lambda:about())
filemenu.add_separator()

root.config(menu=menu)
root.mainloop()


This is what it looks like before opening the window:

Open image

And after:

Open image

Notice how is there no image like this

Open image

horizontally centered in the about dialog?

So, the problem here is, how to show the image? I will ignore solutions with PIL, cause the Replit packager doesn't really seem to work

What I have tried:

 ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ 
Posted
Updated 20-Apr-22 22:19pm

1 solution

Try the following changes to your about function:
Python
def about():
    logoimage = PhotoImage(file="beatcinema.png")   # add this line
	aboutroot = Toplevel(root)
	aboutroot.title("About BeatCinema")
	aboutroot.geometry("235x198")
	aboutroot.iconphoto(False, logoimage)           # use logoimage here
	aboutroot.resizable(False, False)
	aboutlogo = Label(aboutroot, image=logoimage)   # use logoimage here
	aboutlogo.place(relx=0.5, rely=0.0, anchor=CENTER)
    aboutroot.mainloop()                            # add this line
 
Share this answer
 
Comments
Tyrunt.new("Rix") 21-Apr-22 4:57am    
Thanks! I added more "UI components" to the about window, and it just looks fine in Replit!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900