I am creating a tkinter program and ran into this weird error. Here is my code:
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)
The console says:
Error: EOL while scanning string literal.
How can I fix this?
This line has invalid characters:
Label(access_window, text=“Enter a first name: ‘).grid(row=0, sticky=‘W+E’)
# --^ --^ --^ --^
So does this one:
button2 = Button(root, text=“Access Person”, command=access).grid(row=0, column=1)
# --^ --^
In Python, string literals may only be enclosed by normal apostrophes '
or normal quotation marks "
.
To fix the problem, replace each “
and '
with a "
:
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)
Also, the grid
method of every Tkinter widget works in-place (it always returns None
). Thus, you should call it on its own line:
button2 = Button(root, text="Access Person", command=access)
button2.grid(row=0, column=1)
You need to use the same kind of quotation marks to mark the start and end of a string.
So the line you highlighted needs use consistent quotation marks - you shouldn't mix single and double quotes. Your line need to look like this
Label(access_window, text="Enter a first name: ").grid(row=0, sticky=‘W+E’)
Or this
Label(access_window, text='Enter a first name: ').grid(row=0, sticky=‘W+E’)
Not this, where you start with a double quote and end with a single quote
Label(access_window, text=“Enter a first name: ‘).grid(row=0, sticky=‘W+E’)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.