아래의 코드 조각에서 "전역 이름 'start'이 (가) 정의되지 않았습니다."오류가 발생합니다. 그러나 displayImage (img)의 start (panel) 호출은보고자하는 이미지를 GUI에 표시합니다. 그것이 없으면 이미지가 나타나지 않습니다. 그것은 뭔가를하고있을 것입니다. 그러나 위의 오류가 발생합니다. 우분투 12.04에서이 프로그램을 실행하고 있습니다. BTW, 저는 Python과 Tkinter를 처음 접했습니다. 이 오류를 제거하는 방법은 없습니까? 편집 : 이미지 추가는 loadPicture (file)를 호출하는 버튼 클릭으로 런타임 중에 발생합니다.글로벌 이름 'start'가 정의되지 않았습니다. Tkinter
import numpy as np
from Tkinter import *
import cv2 as cv
from tkFileDialog import askopenfilename
import tkSimpleDialog as td
import math as mt
from PIL import ImageTk, Image
### General functions #############################################
def raiseFileChooser():
global filename
filename = askopenfilename()
loadPicture(filename)
def loadPicture(file):
# set global variable for 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 ###########################################
#### get GUI started
root = Tk()
np.set_printoptions(threshold=np.nan) # so I 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 up display panels ###########################
display1 = Frame(app, width=900, height=900, bg="#cccccc")
display1.pack(side=LEFT, fill=BOTH, expand=1)
root.mainloop()
편집 : 스택 트레이스 :
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' is not defined
오류 추적도 줄 번호를 표시해야합니다. 전체 오류 스택 추적을 붙여주십시오. –
또한 tkinter에 익숙하지 않습니다. 'start' 함수가'Tkinter'에 정의되어 있습니까? –
stacktrace를 추가하도록 편집되었습니다. –