I have two .py files in different directories:
E:\Azy Projects\Python\PythonUsingVisualStudio\HellowPython\HellowPython\Operations\Apps\StyleReviews\ReviewSection_1_File.py
E:\Azy Projects\Python\PythonUsingVisualStudio\HellowPython\HellowPython\VisualExpertLogIn.py
in ReviewSection_1_File.py
photo1 = None
def load_image():
global photo1 # Reference the global variable
#photo1 = None
try:
# Load the image
#script_dir = os.path.dirname(os.path.abspath(__file__))
#root_dir = os.path.dirname(os.path.dirname(os.path.dirname(script_dir)))
#image_path = os.path.join(root_dir, "Resources", "Images", "ApImage", "pyImage.png")
image_path = "E:/Azy Projects/Python/PythonUsingVisualStudio/HellowPython/HellowPython/Resources/Images/ApImage/pyImage.png"
img = Image.open(image_path)
img = img.resize((100, 100))
# Convert the image to a PhotoImage object
photo1 = ImageTk.PhotoImage(img)
# Configure the label to display the image
image_label1.configure(image=photo1)
except Exception as e:
print("Error loading image:", e)
def ReviewSection_1 (GetMISUserID, Windos):
# Create a new window for operations admin rights
SizeSet_Top_window = tk.Tk() # Use Tk() for new windows
SizeSet_Top_window.title(" " + Windos)
SizeSet_Top_window.geometry("1000x500")
SizeSet_Top_window.configure(bg="white")
# Add widgets and functionality to the new window
# Example:
label = tk.Label(SizeSet_Top_window, text="Operations Department")
label.pack()
frame = tk.Frame(SizeSet_Top_window , background="bisque",highlightbackground="black", highlightthickness=1)
frame.pack(expand=False)
#frame.pack()
#frame.pack(fill=None, expand=False)
#frame.pack(fill='both', expand=True)
global image_label1
image_label1 = tk.Label(SizeSet_Top_window, text='images')
image_label1.pack(pady=10, padx=10)
load_image()
if I am executing this ReviewSection_1 py file it work fine, but if I am loading this ReviewSection_1 from my another Login.py file, then image is not loading it shows error.
Error loading image: image "pyimage2" doesn't exist
Here my codes:
import tkinter as tk
import VisualExpertMainForm as DashBoard
from Connection import get_SecurityDBConnection
from OPerations.Apps.StyleReviews import ReviewSection_1_File as ReviewSection_1
import pyodbc
from tkinter import ttk
from tkinter import messagebox
from PIL import Image, ImageTk
def login(username, password):
ReviewSection_1.ReviewSection_1 (7,"Main")
return
except pyodbc.Error as e:
# Display error message in the text widget
error_text.config(state='normal') # Enable editing
error_text.delete(1.0, tk.END) # Clear previous error messages
error_text.insert(tk.END, str(e)) # Insert new error message
error_text.config(state='disabled') # Disable editing to make it read-only
error_text.grid(row=4, column=0, columnspan=2, pady=2, padx=5, sticky='we' )
Why does it work directly, and why not if I load the script from another script? Why does it add +1 at the pyimage?