from Tkinter import *
root = Tk()
ticker1 = StringVar()
ticker2 = StringVar()
root.title("Choose Companies")
Label(root,
text = "Company No. 1",
fg = "black",
font ="Helvetica 16 italic").pack()
name = Entry(root,name = ticker1 ).pack()
Label(root,
text = "Company No. 2",
fg = "black",
font ="Helvetica 16 italic").pack()
name1 = Entry(root,name1 = ticker2).pack()
root.mainloop()
The code does not work it gives me this error:
exceptions.TypeError: cannot concatenate 'str' and 'instance' objects
The format to get an entry widget in the python GUI looks correct.
I'm using python 2.7 windows 8.1
The
Entryclass constructor has no keyword parameter namedname1, you can pass aStringVarinstance to thetextvariablekeyword parameter and retrieve text by calling the get() method on thatStringVarinstance. Alternately, you can just call the get() method on theEntryinstance itself.Example: