I'm building an image processing appilcation..the problem is I'm not able to import separate scripts in my main script..I want to use them for various functions..but it shows an error..
can anyone tell me the correct procedure to import script defined for various functions..
`

from Tkinter import *
from PIL import Image, ImageTk, ImageEnhance
import sys
import os
import ttk
import img_func
import en2
import center



root = Tk()
root.wm_title("PhotoGram")
center.center_window(root,1100,700)
#root.tk.call('wm', 'iconbitmap', root, '-default', 'iconfile.ico')

global filename
filename = "ip_img.jpg"

img_func.img_show(root,filename)
img_func.logo_show(root)

Label(root, text="Specify the parameters below and click OK",bg="red",font=("Helvetica", 12)).grid(row=0,columnspan=4)

#Input file
#Label(root, text="Input File:",bg="white").grid(row=1,column=0,sticky=W)

labelIp = StringVar()
labelIp.set("Browse to select an IMAGE                  ")
l1=Label(root, textvariable=labelIp,bg = "white",wraplength=220).grid(row=1, column=1,columnspan=4,sticky=E+W+S+N)

#Function for Browse Ip File  Button
def sel_ip():
 import tkFileDialog


 toplevel = Tk()
 toplevel.withdraw()
 global filename
 filename = tkFileDialog.askopenfilename()
 print filename
 name,ext = os.path.splitext(filename)
 print ext
 name = os.path.basename(name)
 print name

 if ext == ".bmp" or ext == ".xpm" or ext == ".eps" or ext == ".gif" or ext == ".im" or ext == ".jpg" or ext == ".pcd" or ext == ".pcx" or ext == ".xbm" or ext == ".png" or ext == ".ppm" or ext == ".psd" or ext == ".tif" :
  labelIp.set(filename)

  en2.image = Image.open(filename)

  en2.image = en2.image.resize((700,500),Image.ANTIALIAS)


  #im=en2.image.thumbnail((200, 200))
  #img_func.img_show(root,filename)

  en2.tkim = ImageTk.PhotoImage(en2.image.mode,en2.image.size)

  Label(root, image=en2.tkim).grid(row=0, column=10, columnspan=12, rowspan=12,padx=10, sticky=W+E+N+S)

  en2.Enhance(root, "Color", ImageEnhance.Color, 0.0, 4.0).grid(row=3,column=0)
  en2.Enhance(root, "Sharpness", ImageEnhance.Sharpness, -2.0, 2.0).grid(row=3,column=1)
  en2.Enhance(root, "Brightness", ImageEnhance.Brightness, -1.0, 3.0).grid(row=4,column=0)
  en2.Enhance(root, "Contrast", ImageEnhance.Contrast, -1.0, 3.0).grid(row=4,column=1)


  #Label(root, image=tkim).grid(row=5,column=0)


 else:
  labelIp.set("ERROR!! NOT AN IMAGE FILE!!")
  filename = "not_img.jpg"
  img_func.img_show(root,filename)

#Browse IpFile button
b1 = Button(root, text="Click to Browse Input File ...",bg='white',anchor='center',command=sel_ip)
b1.grid(row=1,column=0)

#Enhancement Widgets
en2.image = Image.open(filename)
en2.tkim = ImageTk.PhotoImage(en2.image.mode,en2.image.size)


en2.Enhance(root, "Color", ImageEnhance.Color, 0.0, 4.0).grid(row=3,column=0)
en2.Enhance(root, "Sharpness", ImageEnhance.Sharpness, -2.0, 2.0).grid(row=3,column=1)
en2.Enhance(root, "Brightness", ImageEnhance.Brightness, -1.0, 3.0).grid(row=4,column=0)
en2.Enhance(root, "Contrast", ImageEnhance.Contrast, -1.0, 3.0).grid(row=4,column=1)


#ZOOM IN WIDGET
def zoomin():
 if filename != "ip_img.jpg" and filename != "not_img.jpg":

  print "yes in loop"

  top = Toplevel(root)
  ####zoom in photoimage instance of en2.image code here 

  Label(top, image=en2.tkim).grid(row=0, column=10, columnspan=20, rowspan=20,padx=10, sticky=W+E+N+S)




im = Image.open("zoomin.jpg")
image = im.resize((80,30),Image.ANTIALIAS)
photo = ImageTk.PhotoImage(image)
b=Button(root, image=photo,command=zoomin)
b.grid(row=5,column=0)




root.mainloop()

`

Dani AI

Generated

posted the main script and correctly noted that no traceback was included. Without the exact error it is impossible to be certain, but most "cannot import" problems in setups like this come from a handful of causes: the module file is not on Python's import path, the filename shadows a standard library/module, there is a circular import, or the imported module runs GUI code at import time.

Quick checklist to narrow it down:

  • Confirm the three helper files (img_func.py, en2.py, center.py) are in the same folder as the launcher script or on PYTHONPATH. From the project folder run:
    python -c "import sys,os; print(os.getcwd()); print(sys.path)"
  • Make sure none of the filenames shadow stdlib names and that they end with .py.
  • If the helpers are inside a package folder, add an __init__.py and use package imports or run the app with python -m package.main.

Tkinter- and import-time cautions:

  • Avoid creating Tk() or other GUI widgets at module import. Any module that does root = Tk() at top level will cause side effects when imported and can trigger errors or duplicate root windows. Put GUI creation inside functions and protect runnable modules with:
    if __name__ == "__main__":
      main()
  • Circular imports (main imports en2 while en2 imports main) are common in this layout; break the cycle by passing objects (root, image) as parameters instead of importing the app-level module.

Quick debugging tips and gotchas:

  • Run the script from a terminal to capture the full traceback; the exception type and first failing line point to the issue.
  • Check syntax with python -m py_compile en2.py.
  • For images, ensure Pillow is installed and that ImageTk.PhotoImage is called with an Image object; keep a live reference to PhotoImage objects so Tkinter does not garbage-collect them.

A full traceback plus the failing module's initial lines (imports and any top-level Tk() calls) are what is needed for a targeted diagnosis.

I do not see any error message in your post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.