Python Forum
[Tkinter] How to delete existing label?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] How to delete existing label?
#8
(Jan-07-2021, 03:34 PM)deanhystad Wrote: f'Physical quantity : {name}\nUnit : {unit[0]}\nSymbol : {unit[1]}' constructs a string. just like your code "Physical quantity : " + name + "\nUnit : " + result[0] + "\nSymbol : " + result[1]. It is a bit more compact and I find it easier to read.

A "handle" is just the value returned when you create a widget. In "search_box = Entry(main, width = 34)" the "handle" is the variable "search_box" that references the Entry object returned by the Entry function call. In your code you created the label inside a function.
def result_found(name, result):
    result_lbl = Label(results, text = "Physical quantity :  " + name + "\nUnit :  " + result[0] + "\nSymbol :  " + result[1], justify = LEFT)
    result_lbl.pack(padx = 6, pady = 6, side = LEFT)
The variable "result_lbl" is local to the result_found() function. When the function exits the variable is disposed of. If you want to do things with the Label you have to keep a reference around. I did this by creating the Label in the module scope. Variables declared in the module scope are visible to all functions, classes, whatever in the same module (file). If you want to create the label in a function you will have to do something that makes that label visible to the module context.

I think the best solution is what I posted. Create the label once and use it over and over, only changing the text.


Ok,
I do like to use it by changing the text.
Can you help me with it?
If you can,
I want a demo script, which creates a label, and changes its text.
Smile
Reply


Messages In This Thread
How to delete existing label? - by Oshadha - Jan-06-2021, 05:00 PM
RE: How to delete existing label? - by Larz60+ - Jan-06-2021, 06:17 PM
RE: How to delete existing label? - by Oshadha - Jan-07-2021, 04:26 AM
RE: How to delete existing label? - by deanhystad - Jan-07-2021, 06:12 AM
RE: How to delete existing label? - by Oshadha - Jan-07-2021, 07:30 AM
RE: How to delete existing label? - by Oshadha - Jan-07-2021, 11:26 AM
RE: How to delete existing label? - by deanhystad - Jan-07-2021, 03:34 PM
RE: How to delete existing label? - by Oshadha - Jan-08-2021, 10:32 AM
RE: How to delete existing label? - by deanhystad - Jan-08-2021, 01:42 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020