How to get the Tkinter Label text? How to get the Tkinter Label text? tkinter tkinter

How to get the Tkinter Label text?


To get the value out of a label you can use the cget method, which can be used to get the value of any of the configuration options.

For example:

l = tk.Label(text="hello, world")...print("the label is", l.cget("text"))

You can also treat the object as a dictionary, using the options as keys. Using the same example you can use l["text"].


label = Label(text = 'Hello, World!')print(label['text']) # output is: Hello, World!