tkinter entry widget not updating











up vote
0
down vote

favorite












I've searched everywhere on the web but unfortunately no where did
I find an answer to this question:



after setting a tkinter Entry() widget's textvariable to a textvariable.



the text variable does not update after I have typed text into the entry.



code below:



def saveFileName(self):
if(self.save_file_name != ""):
self.window.destroy()
self.name_not_set = False
print("saving...")
else:
print("notsaving...entry empty")
pass
def cancel(self):
self.name_not_set = False
self.exit = True
self.window.destroy()
print("exiting...")
def askForFilename(self):
self.window = tk.Tk()
self.window.wm_title("enter a file name")
label = Label(self.window,text="please enter a file name:").pack(side="top")
entry = Entry(self.window,textvariable=self.save_file_name).pack()
save = Button(self.window,text="save",command=self.saveFileName).pack()
cancel = Button(self.window,text="cancel",command=self.cancel).pack()
self.window.mainloop()


The necessary variables have been defined and these methods are part
of a class which is a tk.TK() instance.



my attempt to enter a name :(console log
this problem is very bothersome
:( very sad :(



Thank you and merry christmas in advance!










share|improve this question


















  • 2




    Please show how you defined the variable.
    – Bryan Oakley
    Nov 19 at 1:10










  • Note that statements like label = Label(self.window,text="please enter a file name:").pack(side="top") will assign the result of calling pack to the variable named label, which can often cause problems (maybe yours).
    – martineau
    Nov 19 at 1:48

















up vote
0
down vote

favorite












I've searched everywhere on the web but unfortunately no where did
I find an answer to this question:



after setting a tkinter Entry() widget's textvariable to a textvariable.



the text variable does not update after I have typed text into the entry.



code below:



def saveFileName(self):
if(self.save_file_name != ""):
self.window.destroy()
self.name_not_set = False
print("saving...")
else:
print("notsaving...entry empty")
pass
def cancel(self):
self.name_not_set = False
self.exit = True
self.window.destroy()
print("exiting...")
def askForFilename(self):
self.window = tk.Tk()
self.window.wm_title("enter a file name")
label = Label(self.window,text="please enter a file name:").pack(side="top")
entry = Entry(self.window,textvariable=self.save_file_name).pack()
save = Button(self.window,text="save",command=self.saveFileName).pack()
cancel = Button(self.window,text="cancel",command=self.cancel).pack()
self.window.mainloop()


The necessary variables have been defined and these methods are part
of a class which is a tk.TK() instance.



my attempt to enter a name :(console log
this problem is very bothersome
:( very sad :(



Thank you and merry christmas in advance!










share|improve this question


















  • 2




    Please show how you defined the variable.
    – Bryan Oakley
    Nov 19 at 1:10










  • Note that statements like label = Label(self.window,text="please enter a file name:").pack(side="top") will assign the result of calling pack to the variable named label, which can often cause problems (maybe yours).
    – martineau
    Nov 19 at 1:48















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I've searched everywhere on the web but unfortunately no where did
I find an answer to this question:



after setting a tkinter Entry() widget's textvariable to a textvariable.



the text variable does not update after I have typed text into the entry.



code below:



def saveFileName(self):
if(self.save_file_name != ""):
self.window.destroy()
self.name_not_set = False
print("saving...")
else:
print("notsaving...entry empty")
pass
def cancel(self):
self.name_not_set = False
self.exit = True
self.window.destroy()
print("exiting...")
def askForFilename(self):
self.window = tk.Tk()
self.window.wm_title("enter a file name")
label = Label(self.window,text="please enter a file name:").pack(side="top")
entry = Entry(self.window,textvariable=self.save_file_name).pack()
save = Button(self.window,text="save",command=self.saveFileName).pack()
cancel = Button(self.window,text="cancel",command=self.cancel).pack()
self.window.mainloop()


The necessary variables have been defined and these methods are part
of a class which is a tk.TK() instance.



my attempt to enter a name :(console log
this problem is very bothersome
:( very sad :(



Thank you and merry christmas in advance!










share|improve this question













I've searched everywhere on the web but unfortunately no where did
I find an answer to this question:



after setting a tkinter Entry() widget's textvariable to a textvariable.



the text variable does not update after I have typed text into the entry.



code below:



def saveFileName(self):
if(self.save_file_name != ""):
self.window.destroy()
self.name_not_set = False
print("saving...")
else:
print("notsaving...entry empty")
pass
def cancel(self):
self.name_not_set = False
self.exit = True
self.window.destroy()
print("exiting...")
def askForFilename(self):
self.window = tk.Tk()
self.window.wm_title("enter a file name")
label = Label(self.window,text="please enter a file name:").pack(side="top")
entry = Entry(self.window,textvariable=self.save_file_name).pack()
save = Button(self.window,text="save",command=self.saveFileName).pack()
cancel = Button(self.window,text="cancel",command=self.cancel).pack()
self.window.mainloop()


The necessary variables have been defined and these methods are part
of a class which is a tk.TK() instance.



my attempt to enter a name :(console log
this problem is very bothersome
:( very sad :(



Thank you and merry christmas in advance!







python tkinter tkinter-entry






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 0:38









C Lu

284




284








  • 2




    Please show how you defined the variable.
    – Bryan Oakley
    Nov 19 at 1:10










  • Note that statements like label = Label(self.window,text="please enter a file name:").pack(side="top") will assign the result of calling pack to the variable named label, which can often cause problems (maybe yours).
    – martineau
    Nov 19 at 1:48
















  • 2




    Please show how you defined the variable.
    – Bryan Oakley
    Nov 19 at 1:10










  • Note that statements like label = Label(self.window,text="please enter a file name:").pack(side="top") will assign the result of calling pack to the variable named label, which can often cause problems (maybe yours).
    – martineau
    Nov 19 at 1:48










2




2




Please show how you defined the variable.
– Bryan Oakley
Nov 19 at 1:10




Please show how you defined the variable.
– Bryan Oakley
Nov 19 at 1:10












Note that statements like label = Label(self.window,text="please enter a file name:").pack(side="top") will assign the result of calling pack to the variable named label, which can often cause problems (maybe yours).
– martineau
Nov 19 at 1:48






Note that statements like label = Label(self.window,text="please enter a file name:").pack(side="top") will assign the result of calling pack to the variable named label, which can often cause problems (maybe yours).
– martineau
Nov 19 at 1:48














1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










A textvariable associated with an Entry should be a StringVar(). I don't se any such declaration in your code.



self.save_file_name = StringVar()


To set and get the value of a StringVar() you must use the set() or get() method, eg.



def saveFileName(self):
if(self.save_file_name.get() != ""):
self.window.destroy()
# etc, etc.


Also, don't create more than one instance of Tk() as in:



def askForFilename(self):
self.window = tk.Tk()


Use Toplevel() instead. Or even better: use the tkinter filedialogs.






share|improve this answer





















  • Thank you! I did set the StringVar variable in the datafield. which I didn't include in my code above so sorry for the inclarity(if that's a word) but the issue appears to be the second thing you mentioned. I forgot to call .get() on the StringVar, :D
    – C Lu
    Nov 23 at 2:43













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53366916%2ftkinter-entry-widget-not-updating%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










A textvariable associated with an Entry should be a StringVar(). I don't se any such declaration in your code.



self.save_file_name = StringVar()


To set and get the value of a StringVar() you must use the set() or get() method, eg.



def saveFileName(self):
if(self.save_file_name.get() != ""):
self.window.destroy()
# etc, etc.


Also, don't create more than one instance of Tk() as in:



def askForFilename(self):
self.window = tk.Tk()


Use Toplevel() instead. Or even better: use the tkinter filedialogs.






share|improve this answer





















  • Thank you! I did set the StringVar variable in the datafield. which I didn't include in my code above so sorry for the inclarity(if that's a word) but the issue appears to be the second thing you mentioned. I forgot to call .get() on the StringVar, :D
    – C Lu
    Nov 23 at 2:43

















up vote
0
down vote



accepted










A textvariable associated with an Entry should be a StringVar(). I don't se any such declaration in your code.



self.save_file_name = StringVar()


To set and get the value of a StringVar() you must use the set() or get() method, eg.



def saveFileName(self):
if(self.save_file_name.get() != ""):
self.window.destroy()
# etc, etc.


Also, don't create more than one instance of Tk() as in:



def askForFilename(self):
self.window = tk.Tk()


Use Toplevel() instead. Or even better: use the tkinter filedialogs.






share|improve this answer





















  • Thank you! I did set the StringVar variable in the datafield. which I didn't include in my code above so sorry for the inclarity(if that's a word) but the issue appears to be the second thing you mentioned. I forgot to call .get() on the StringVar, :D
    – C Lu
    Nov 23 at 2:43















up vote
0
down vote



accepted







up vote
0
down vote



accepted






A textvariable associated with an Entry should be a StringVar(). I don't se any such declaration in your code.



self.save_file_name = StringVar()


To set and get the value of a StringVar() you must use the set() or get() method, eg.



def saveFileName(self):
if(self.save_file_name.get() != ""):
self.window.destroy()
# etc, etc.


Also, don't create more than one instance of Tk() as in:



def askForFilename(self):
self.window = tk.Tk()


Use Toplevel() instead. Or even better: use the tkinter filedialogs.






share|improve this answer












A textvariable associated with an Entry should be a StringVar(). I don't se any such declaration in your code.



self.save_file_name = StringVar()


To set and get the value of a StringVar() you must use the set() or get() method, eg.



def saveFileName(self):
if(self.save_file_name.get() != ""):
self.window.destroy()
# etc, etc.


Also, don't create more than one instance of Tk() as in:



def askForFilename(self):
self.window = tk.Tk()


Use Toplevel() instead. Or even better: use the tkinter filedialogs.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 5:09









figbeam

2,265137




2,265137












  • Thank you! I did set the StringVar variable in the datafield. which I didn't include in my code above so sorry for the inclarity(if that's a word) but the issue appears to be the second thing you mentioned. I forgot to call .get() on the StringVar, :D
    – C Lu
    Nov 23 at 2:43




















  • Thank you! I did set the StringVar variable in the datafield. which I didn't include in my code above so sorry for the inclarity(if that's a word) but the issue appears to be the second thing you mentioned. I forgot to call .get() on the StringVar, :D
    – C Lu
    Nov 23 at 2:43


















Thank you! I did set the StringVar variable in the datafield. which I didn't include in my code above so sorry for the inclarity(if that's a word) but the issue appears to be the second thing you mentioned. I forgot to call .get() on the StringVar, :D
– C Lu
Nov 23 at 2:43






Thank you! I did set the StringVar variable in the datafield. which I didn't include in my code above so sorry for the inclarity(if that's a word) but the issue appears to be the second thing you mentioned. I forgot to call .get() on the StringVar, :D
– C Lu
Nov 23 at 2:43




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53366916%2ftkinter-entry-widget-not-updating%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin