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)
python tkinter grid
add a comment |
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)
python tkinter grid
Use this Hello, Again as a pattern.
– stovfl
Nov 9 at 21:47
add a comment |
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)
python tkinter grid
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
python tkinter grid
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
add a comment |
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
add a comment |
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()
@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
add a comment |
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()
@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
add a comment |
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()
@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
add a comment |
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()
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()
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
add a comment |
@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
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Use this Hello, Again as a pattern.
– stovfl
Nov 9 at 21:47