Why does Python tkinter label widget not update?









up vote
0
down vote

favorite












class First_Frame(Frame):
def __init__(self,master):
super().__init__(master)
self.grid()
self.widgets()

def widgets(self):
self.commandent1=StringVar()
self.commandent1.set("tutaj bedzie sie pokazywal aktualny status")
self.img=Image.open("database.XPM","r")
self.image_true=ImageTk.PhotoImage(self.img)
self.label=Label(self,image=self.image_true).grid()
self.label2=Label(self,text="twoje gui uzytkownika").grid()
self.widgets_2()

def widgets_2(self):
self.status_text=Label(self,text=self.commandent1.get())
self.entry1=Entry(self)
self.entry1.bind("<Return>",self.update_status)
self.entry1.grid()
self.status_text.grid()
def update_status(self):
self.x=self.entry1.get()
self.commandent1.set(self.x)









share|improve this question























  • Use this Hello, Again as a pattern.
    – stovfl
    Nov 9 at 21:47














up vote
0
down vote

favorite












class First_Frame(Frame):
def __init__(self,master):
super().__init__(master)
self.grid()
self.widgets()

def widgets(self):
self.commandent1=StringVar()
self.commandent1.set("tutaj bedzie sie pokazywal aktualny status")
self.img=Image.open("database.XPM","r")
self.image_true=ImageTk.PhotoImage(self.img)
self.label=Label(self,image=self.image_true).grid()
self.label2=Label(self,text="twoje gui uzytkownika").grid()
self.widgets_2()

def widgets_2(self):
self.status_text=Label(self,text=self.commandent1.get())
self.entry1=Entry(self)
self.entry1.bind("<Return>",self.update_status)
self.entry1.grid()
self.status_text.grid()
def update_status(self):
self.x=self.entry1.get()
self.commandent1.set(self.x)









share|improve this question























  • Use this Hello, Again as a pattern.
    – stovfl
    Nov 9 at 21:47












up vote
0
down vote

favorite









up vote
0
down vote

favorite











class First_Frame(Frame):
def __init__(self,master):
super().__init__(master)
self.grid()
self.widgets()

def widgets(self):
self.commandent1=StringVar()
self.commandent1.set("tutaj bedzie sie pokazywal aktualny status")
self.img=Image.open("database.XPM","r")
self.image_true=ImageTk.PhotoImage(self.img)
self.label=Label(self,image=self.image_true).grid()
self.label2=Label(self,text="twoje gui uzytkownika").grid()
self.widgets_2()

def widgets_2(self):
self.status_text=Label(self,text=self.commandent1.get())
self.entry1=Entry(self)
self.entry1.bind("<Return>",self.update_status)
self.entry1.grid()
self.status_text.grid()
def update_status(self):
self.x=self.entry1.get()
self.commandent1.set(self.x)









share|improve this question















class First_Frame(Frame):
def __init__(self,master):
super().__init__(master)
self.grid()
self.widgets()

def widgets(self):
self.commandent1=StringVar()
self.commandent1.set("tutaj bedzie sie pokazywal aktualny status")
self.img=Image.open("database.XPM","r")
self.image_true=ImageTk.PhotoImage(self.img)
self.label=Label(self,image=self.image_true).grid()
self.label2=Label(self,text="twoje gui uzytkownika").grid()
self.widgets_2()

def widgets_2(self):
self.status_text=Label(self,text=self.commandent1.get())
self.entry1=Entry(self)
self.entry1.bind("<Return>",self.update_status)
self.entry1.grid()
self.status_text.grid()
def update_status(self):
self.x=self.entry1.get()
self.commandent1.set(self.x)






python tkinter grid






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 23:36









Mike - SMT

8,4932934




8,4932934










asked Nov 9 at 21:29









Filip Weiss

63




63











  • Use this Hello, Again as a pattern.
    – stovfl
    Nov 9 at 21:47
















  • Use this Hello, Again as a pattern.
    – stovfl
    Nov 9 at 21:47















Use this Hello, Again as a pattern.
– stovfl
Nov 9 at 21:47




Use this Hello, Again as a pattern.
– stovfl
Nov 9 at 21:47












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










You have 2 main reasons your Label (not text) widget is not updating.



Reason 1. You need to handle the event that is being passed to update_status from the binding. To do this just add event or any argument name really you want. I just use event for readability.



def update_status(self, event):


Reason 2. You need to and the less obvious reason here for some is the way you are using your StringVar() on the label widget. Here you are assigning the current text value of the StringVar() only once and never again. To properly use the StringVar() with a label widget you will need to assign the StringVar() to a textvariable argument and not a text argument.



Like this:



Label(self,textvariable=self.commandent1).grid()


Note I took out the image portion of your code as it was irrelevant to the question. Your final code should look something like this:



from tkinter import *

class First_Frame(Frame):
def __init__(self, master):
super().__init__()
self.grid()
self.widgets()

def widgets(self):
self.commandent1 = StringVar()
self.commandent1.set("tutaj bedzie sie pokazywal aktualny status")
Label(self,text="twoje gui uzytkownika").grid()
self.widgets_2()

def widgets_2(self):
self.entry1 = Entry(self)
self.entry1.bind("<Return>", self.update_status)
self.entry1.grid()
Label(self,textvariable=self.commandent1).grid()

def update_status(self, event):
self.commandent1.set(self.entry1.get())


root = Tk()
First_Frame(root)
root.mainloop()





share|improve this answer




















  • @FilipWeiss If my answer helped you please make sure to select the check mark next to the answer to indicate your problem was solved.
    – Mike - SMT
    Nov 10 at 14:42










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%2f53233491%2fwhy-does-python-tkinter-label-widget-not-update%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










You have 2 main reasons your Label (not text) widget is not updating.



Reason 1. You need to handle the event that is being passed to update_status from the binding. To do this just add event or any argument name really you want. I just use event for readability.



def update_status(self, event):


Reason 2. You need to and the less obvious reason here for some is the way you are using your StringVar() on the label widget. Here you are assigning the current text value of the StringVar() only once and never again. To properly use the StringVar() with a label widget you will need to assign the StringVar() to a textvariable argument and not a text argument.



Like this:



Label(self,textvariable=self.commandent1).grid()


Note I took out the image portion of your code as it was irrelevant to the question. Your final code should look something like this:



from tkinter import *

class First_Frame(Frame):
def __init__(self, master):
super().__init__()
self.grid()
self.widgets()

def widgets(self):
self.commandent1 = StringVar()
self.commandent1.set("tutaj bedzie sie pokazywal aktualny status")
Label(self,text="twoje gui uzytkownika").grid()
self.widgets_2()

def widgets_2(self):
self.entry1 = Entry(self)
self.entry1.bind("<Return>", self.update_status)
self.entry1.grid()
Label(self,textvariable=self.commandent1).grid()

def update_status(self, event):
self.commandent1.set(self.entry1.get())


root = Tk()
First_Frame(root)
root.mainloop()





share|improve this answer




















  • @FilipWeiss If my answer helped you please make sure to select the check mark next to the answer to indicate your problem was solved.
    – Mike - SMT
    Nov 10 at 14:42














up vote
0
down vote



accepted










You have 2 main reasons your Label (not text) widget is not updating.



Reason 1. You need to handle the event that is being passed to update_status from the binding. To do this just add event or any argument name really you want. I just use event for readability.



def update_status(self, event):


Reason 2. You need to and the less obvious reason here for some is the way you are using your StringVar() on the label widget. Here you are assigning the current text value of the StringVar() only once and never again. To properly use the StringVar() with a label widget you will need to assign the StringVar() to a textvariable argument and not a text argument.



Like this:



Label(self,textvariable=self.commandent1).grid()


Note I took out the image portion of your code as it was irrelevant to the question. Your final code should look something like this:



from tkinter import *

class First_Frame(Frame):
def __init__(self, master):
super().__init__()
self.grid()
self.widgets()

def widgets(self):
self.commandent1 = StringVar()
self.commandent1.set("tutaj bedzie sie pokazywal aktualny status")
Label(self,text="twoje gui uzytkownika").grid()
self.widgets_2()

def widgets_2(self):
self.entry1 = Entry(self)
self.entry1.bind("<Return>", self.update_status)
self.entry1.grid()
Label(self,textvariable=self.commandent1).grid()

def update_status(self, event):
self.commandent1.set(self.entry1.get())


root = Tk()
First_Frame(root)
root.mainloop()





share|improve this answer




















  • @FilipWeiss If my answer helped you please make sure to select the check mark next to the answer to indicate your problem was solved.
    – Mike - SMT
    Nov 10 at 14:42












up vote
0
down vote



accepted







up vote
0
down vote



accepted






You have 2 main reasons your Label (not text) widget is not updating.



Reason 1. You need to handle the event that is being passed to update_status from the binding. To do this just add event or any argument name really you want. I just use event for readability.



def update_status(self, event):


Reason 2. You need to and the less obvious reason here for some is the way you are using your StringVar() on the label widget. Here you are assigning the current text value of the StringVar() only once and never again. To properly use the StringVar() with a label widget you will need to assign the StringVar() to a textvariable argument and not a text argument.



Like this:



Label(self,textvariable=self.commandent1).grid()


Note I took out the image portion of your code as it was irrelevant to the question. Your final code should look something like this:



from tkinter import *

class First_Frame(Frame):
def __init__(self, master):
super().__init__()
self.grid()
self.widgets()

def widgets(self):
self.commandent1 = StringVar()
self.commandent1.set("tutaj bedzie sie pokazywal aktualny status")
Label(self,text="twoje gui uzytkownika").grid()
self.widgets_2()

def widgets_2(self):
self.entry1 = Entry(self)
self.entry1.bind("<Return>", self.update_status)
self.entry1.grid()
Label(self,textvariable=self.commandent1).grid()

def update_status(self, event):
self.commandent1.set(self.entry1.get())


root = Tk()
First_Frame(root)
root.mainloop()





share|improve this answer












You have 2 main reasons your Label (not text) widget is not updating.



Reason 1. You need to handle the event that is being passed to update_status from the binding. To do this just add event or any argument name really you want. I just use event for readability.



def update_status(self, event):


Reason 2. You need to and the less obvious reason here for some is the way you are using your StringVar() on the label widget. Here you are assigning the current text value of the StringVar() only once and never again. To properly use the StringVar() with a label widget you will need to assign the StringVar() to a textvariable argument and not a text argument.



Like this:



Label(self,textvariable=self.commandent1).grid()


Note I took out the image portion of your code as it was irrelevant to the question. Your final code should look something like this:



from tkinter import *

class First_Frame(Frame):
def __init__(self, master):
super().__init__()
self.grid()
self.widgets()

def widgets(self):
self.commandent1 = StringVar()
self.commandent1.set("tutaj bedzie sie pokazywal aktualny status")
Label(self,text="twoje gui uzytkownika").grid()
self.widgets_2()

def widgets_2(self):
self.entry1 = Entry(self)
self.entry1.bind("<Return>", self.update_status)
self.entry1.grid()
Label(self,textvariable=self.commandent1).grid()

def update_status(self, event):
self.commandent1.set(self.entry1.get())


root = Tk()
First_Frame(root)
root.mainloop()






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 23:34









Mike - SMT

8,4932934




8,4932934











  • @FilipWeiss If my answer helped you please make sure to select the check mark next to the answer to indicate your problem was solved.
    – Mike - SMT
    Nov 10 at 14:42
















  • @FilipWeiss If my answer helped you please make sure to select the check mark next to the answer to indicate your problem was solved.
    – Mike - SMT
    Nov 10 at 14:42















@FilipWeiss If my answer helped you please make sure to select the check mark next to the answer to indicate your problem was solved.
– Mike - SMT
Nov 10 at 14:42




@FilipWeiss If my answer helped you please make sure to select the check mark next to the answer to indicate your problem was solved.
– Mike - SMT
Nov 10 at 14:42

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233491%2fwhy-does-python-tkinter-label-widget-not-update%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

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo