Unknown syntax error on creating a simple widget in Tkinter
I was following this tutorial (http://sebsauvage.net/python/gui/#add_button) on making widgets with Tkinter. I have been making sure to follow it very carefully but, when I run it now in step 10, I get an "Invalid Syntax" Error. Here the code:
import tkinter
class simpleapp_tk(tkinter.Tk):
def __init__(self,parent):
tkinter.Tk.__init__(self,parent)
self.parent = parent
self.initialize()
def initialize(self):
self.grid()
self.entry = tkinter.Entry(self)
self.entry.grid(column=0,row=0,sticky='EW')
button = tkinter.Button(self,text=u"Click me !")
button.grid(column=1,row=0)
if __name__ == "__main__":
app = simpleapp_tk(None)
app.title('my application')
app.ma开发者_运维技巧inloop()
The IDLE points the error is in this line, selecting the second quotation marks:
button = tkinter.Button(self,text=u"Click me !**"**)
The tutorial was written in Python 2, but I'm using Python 3. Can anyone see what is the error and what to do to fix it (in Python 3)?
Thanks in advance for any help, I am new to programming and English is not my native language.
Replace u"Click me !**"
with "Click me !**"
The u
indicates a Unicode string (type unicode
instead of str
) in Python 2, but in Python 3, the distinction between the str
and unicode
types is gone and the u
is scrapped.
There is no u
prefix for unicode strings in Python 3.
精彩评论