0

I am new to tkinter please help me to solve this problem

i have a created a function of frame and gave a arugument to display image on frame on clicking the home button but its not displaying

what i shd do now its not showing any error too

This is code has no classes

from tkinter import *
from tkinter import ttk
from PIL import Image,ImageTk 
import os 
import pickle 
import mysql.connector  as sql
from tkinter import messagebox

def click_home():
    """set to default home tab where details like no. of students, employees, department shows """

    home_frame = Frame(root)
    home_frame.place(x=120, y=105, height=440, width=910)

    home_dashboard_frame = ImageTk.PhotoImage(file=r'files\Sublime Light1.jpg')
    home_panel = Label(home_frame, image=home_dashboard_frame, bg="white")
    home_panel.pack(fill='both', expand='yes')

root = Tk()
root.geometry("1067x600")
root.title("Dashboard")
root.resizable(False, False) 
#root.iconbitmap('images\\logo.ico')

bg = ImageTk.PhotoImage(file="files\Dashboard1.jpg")
lbl_bg = Label(root,image=bg)
lbl_bg.place(x=0,y=0,relwidth=1,relheight=1)


home_r=Image.open('Pics\\home.png')
home_r=home_r.resize((50, 50), Image.ANTIALIAS)
home = ImageTk.PhotoImage(home_r)
home_button = Button(root, image=home,font=("yu gothic ui", 13, "bold"), relief=FLAT, activebackground="white", borderwidth=0, background="white", cursor="hand2",command=click_home)
home_button.place(x=40, y=113)


manage_r=Image.open('Pics\\manage.png')
manage_r=manage_r.resize((50, 50), Image.ANTIALIAS)
manage = ImageTk.PhotoImage(manage_r)
manage_button = Button(root, image=manage,font=("yu gothic ui", 13, "bold"), relief=FLAT, activebackground="white", borderwidth=0, background="white", cursor="hand2")
manage_button.place(x=38, y=205)

view_r=Image.open('Pics\\view.png')
view_r=view_r.resize((50, 50), Image.ANTIALIAS)
view = ImageTk.PhotoImage(view_r)
view_button = Button(root, image=view,font=("yu gothic ui", 13, "bold"), relief=FLAT, activebackground="white", borderwidth=0, background="white", cursor="hand2")
view_button.place(x=36, y=299)

setting_r = Image.open('Pics\\setting.png')
setting_r=setting_r.resize((50, 50), Image.ANTIALIAS)
setting = ImageTk.PhotoImage(setting_r)
setting_button = Button(root, image=setting,font=("yu gothic ui", 13, "bold"), relief=FLAT, activebackground="white", borderwidth=0, background="white", cursor="hand2")
setting_button.place(x=38, y=395)

exit_1_r=Image.open('Pics\\exit_button.png')
exit_1_r=exit_1_r.resize((50, 50), Image.ANTIALIAS)
exit_1 = ImageTk.PhotoImage(exit_1_r)
exit_button = Button(root, image=exit_1,font=("yu gothic ui", 13, "bold"), relief=FLAT, activebackground="white", borderwidth=0, background="white", cursor="hand2")
exit_button.place(x=37, y=490)

logout = ImageTk.PhotoImage(file='Pics\logout.png')
logout_button = Button(root, image=logout,font=("yu gothic ui", 13, "bold"), relief=FLAT, activebackground="white", borderwidth=0, background="white", cursor="hand2")
logout_button.place(x=940, y=56)



root.mainloop()

any edits you want do u can ........

Thanks

acw1668
  • 40,144
  • 5
  • 22
  • 34
  • 2
    You have already asked the question and it is marked as duplicate. Did you try to understand the cause of your issue in the reference link in your closed duplicate question? It is nothing related to whether class is used or not. It is because `home_dashboard_frame` is a local variable that will be garbage collected after the function exits. Save an reference to the image like `home_panel.image = home_dashboard_frame`. – acw1668 Dec 29 '21 at 10:19
  • Have you tried showing the image minus the button feature, i.e. showing it on startup? (Basic error testing would be handy for others) – Larry the Llama Dec 29 '21 at 11:01

0 Answers0