Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23247

Python Image Error in different Directories

$
0
0

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 = Nonedef 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_label1image_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 tkimport VisualExpertMainForm as DashBoardfrom Connection import get_SecurityDBConnection

from OPerations.Apps.StyleReviews import ReviewSection_1_File as ReviewSection_1

import pyodbcfrom tkinter import ttkfrom tkinter import messageboxfrom PIL import Image, ImageTkdef 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 it work directly and why not if I load the script from another script ? why it add +1 at the pyimage ?


Viewing all articles
Browse latest Browse all 23247

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>