2014-03-31 3 views
0

나는 tkinter 프로그램을 만들고이 이상한 오류가났습니다.오류? 그림을 그릴 수 없습니다

from Tkinter import * 
def get_info(key):  
    pass 
def create_new(): 
    create = Toplevel(root) 
    create.title('Create A New Contact') 
    Label(create, text='Name: ').grid(row=0, sticky=W+E) 
    name = Entry(create, width=8).grid(row=1, sticky=W+E) 
    Label(create, text='Address(ex. 1111 Main St, MyCity, Anystate 12345): ', wrapLength=1).grid(row=2, sticky=W+E) 
    address = Entry(create, width=8).grid(row=3, sticky=W+E) 
def access(): 
    access_window = Toplevel(root) 
    access_window.title("Access a Contact") 
    Label(access_window, text=“Enter a first name: ‘).grid(row=0, sticky=‘W+E’)#Error here 
    access_key = Entry(access_window, width=8).grid(row=0, sticky='W+E') 
    Button(access_window, text="Submit", command=lambda: get_info(access_key.get('0.0', 'end-1c'))).grid(row=2, sticky='W+E') 
root = Tk() 
root.title('Address Book') 
button1 = Button(root, text="Create New", command=create_new).grid(row=0, column=0) 
button2 = Button(root, text=“Access Person”, command=access).grid(row=0, column=1) 

콘솔은 말한다 :

Error: EOL while scanning string literal. 

가 어떻게이 문제를 해결할 수 있습니다 여기 내 코드는?

답변

2

문자열의 시작과 끝을 표시하려면 동일한 종류의 따옴표를 사용해야합니다.

그래서 강조 표시된 라인은 일관된 따옴표를 사용해야합니다. 작은 따옴표와 큰 따옴표를 섞어서는 안됩니다.

Label(access_window, text=“Enter a first name: ‘).grid(row=0, sticky=‘W+E’) 
3

이 줄은 잘못된 문자가 있습니다 :

Label(access_window, text=“Enter a first name: ‘).grid(row=0, sticky=‘W+E’) 
#      --^     --^     --^ --^ 

그래서이 일을 수행합니다

파이썬에서
button2 = Button(root, text=“Access Person”, command=access).grid(row=0, column=1) 
#       --^   --^ 

은 문자열 리터럴은 정상 아포스트로피 ' 또는 일반 인용 부호 "에 의해 둘러싸인 할 수있다.


이 문제를 해결 각 를 대체 할 " : 또한


Label(access_window, text="Enter a first name: ").grid(row=0, sticky="W+E") 

button2 = Button(root, text="Access Person", command=access).grid(row=0, column=1) 
, 모든 Tkinter를 위젯의 grid 방법은 (항상 None을 반환)에 적절한 작동 . 따라서 다음 줄을 호출해야합니다.

button2 = Button(root, text="Access Person", command=access) 
button2.grid(row=0, column=1) 
+0

내가 동의하지 않는 당신의 라인은 작은 따옴표로 당신은 큰 따옴표로 시작하는 곳이, 아니이

Label(access_window, text="Enter a first name: ").grid(row=0, sticky=‘W+E’) 

또는이

Label(access_window, text='Enter a first name: ').grid(row=0, sticky=‘W+E’) 

같이하고 종료합니다 이 질문과 함께 - 그러나 문제는 그의 코멘트에 의해 표시되는 Label (access_window ...) 행에 문제가 있음을 유의하십시오. – dannymilsom

+0

@dannymilsom - 오, 나는 거기에서도 그렇게하고있는 것을 보지 못했습니다. 내 대답을 편집하겠습니다. – iCodez

관련 문제