python - Global name 'start' is not defined: Tkinter -
i getting error "global name 'start' not defined" code snippet below. start(panel) call in displayimage(img) causes image want see displayed in gui; without no image shows up; must doing something. yet above error. i'm running program in ubuntu 12.04. btw, new both python , tkinter. way rid of error? edit: adding of image occurs during runtime button click calls loadpicture(file).
import numpy np tkinter import * import cv2 cv tkfiledialog import askopenfilename import tksimpledialog td import math mt pil import imagetk, image ### general functions ############################################# def raisefilechooser(): global filename filename = askopenfilename() loadpicture(filename) def loadpicture(file): # set global variable other uses global img img = cv.imread(file, 1) img = cv.cvtcolor(img, cv.color_rgb2bgr) displayimage(img, display1) def displayimage(image, panel): temp = image.fromarray(image) bk = imagetk.photoimage(temp) bklabel = label(display1, image = bk) bklabel.place(x=0, y=0, relwidth=1, relheight=1) start(panel) ### start app ########################################### #### gui started root = tk() np.set_printoptions(threshold=np.nan) # can print entire arrays ### global variables #################################### relstatus = stringvar() relstatus.set(none) text = stringvar() filepath = stringvar() filename = "no file chosen" img = none gsc = none estatus = stringvar() estatus.set(none) display1 = none display2 = none ### gui ################################################# root.title("picture transformer") root.geometry("700x600") app = panedwindow(root) app.pack(padx=20, pady=20) #button panel############## buttonpanel = frame(app,width=200, height = 400) buttonpanel.pack(side=left) chooser = button(buttonpanel, text="choose file", height=1, width=9, command=raisefilechooser) chooser.pack() #set display panels ########################### display1 = frame(app, width=900, height=900, bg="#cccccc") display1.pack(side=left, fill=both, expand=1) root.mainloop()
edit: stacktrace:
traceback (most recent call last): file "/usr/lib/python2.7/lib-tk/tkinter.py", line 1413, in __call__ return self.func(*args) file "hw2.py", line 78, in raisefilechooser loadpicture(filename) file "hw2.py", line 86, in loadpicture start(panel) nameerror: global name 'start' not defined
the error telling what's wrong -- there no global start
function in code. in fact, near can tell, there's no start
method anywhere, in object creating. why think should calling function named start
? there documentation somewhere telling this?
my guess is, you're running in idle, , when call non-existent start
function, script crashes. when script crashes returns idle, , whatever windows had created point visible.
the obvious problem have in code aren't creating root window. somewhere in script, before create widgets or instances of stringvar
need this:
root = tk()
Comments
Post a Comment