Hi I\'ve been struggling to get this to work, each time i change something I receive another error. I\'ve been trying to create an entry box with a function and then get the var
If you make myFunc
A method if the class (which you might be trying to do; it's hard to know because your indentation is wrong), you don't have to pass anything to myFunc
. That function has access to everything in the class, so it can get what it needs, when it needs it. That lets you eliminate the use of lambda
, which helps reduce complexity.
Also, you normally don't need a StringVar
at all, it's just one more thing to keep track of. However, if you really need the label and entry to show exactly the same data, have them share the same textvariable and the text is updated automatically without you having to call a function, or get the value from the widget, or set the value n the label.
Here's an example without using StringVar
:
class My_Class:
def start(self):
...
self.entry_box = Entry(self.root)
self.button = Button(..., command = self.myFunc)
...
def myFunc(self):
s = self.entry_box.get()
self.lab = Label(..., text = s)
...