0

Scenario is something like this:- I created a label named as Username and created a Entry as entry1 withe the code like below. And I created another label Label2 where I want to display the same value inserted above in entry1. Code is something like below:

from Tkinter import *
root = Tk()

test=StringVar()

label1=Label(root,text='Username').grid()
entry1 = Entry(root, textvariable=test)
entry1.grid()

#print test
button1 = Button(root, text = 'Login',).grid()

label2=Label(root,textvariable= test).grid()

root.mainloop()

PS: This is the code I am working with, I am a newbie in Python and Tkinter so please suggest the easiest approach.

sigdelsanjog
  • 528
  • 1
  • 11
  • 30
  • So what is wrong with the code you have? Can you provide a simple, minimal working example that we can play with? e.g. your sample code doesn't define root, doesn't enter the mainloop anywhere, etc. – mgilson Jan 09 '15 at 18:15
  • Side note, in your example code, `button1`, `label1` and `label2` will all have the value of `None` since that is what `Widget.grid` returns. – mgilson Jan 09 '15 at 18:16
  • See also [Python TkInter - AttributeError: 'NoneType' object has no attribute 'get'](http://stackoverflow.com/q/1101750/953482), regarding assignment and `grid` – Kevin Jan 09 '15 at 18:17
  • @mgilson I have edited the code and now this is the code that I am using. Would you please go through the code and help me. Thank you in advance. – sigdelsanjog Jan 09 '15 at 18:32
  • @algosig -- your code works for me (When I type in the entry, stuff appears in the label). – mgilson Jan 09 '15 at 18:35
  • @mgilson I am now a joke to ask the question which is totally right, Just workde after I restarted the text editor and the terminal. I don't know what kind of error was that. – sigdelsanjog Jan 09 '15 at 18:42
  • @algosig -- No problem, the question will probably get closed because it "can't be reproduced due to a typographical error". The fact that it is a close option shows that this sort of thing happens A LOT. Alternatively, you can choose to delete the question if you'd rather (look for the "delete" button under the post). – mgilson Jan 09 '15 at 18:51

0 Answers0