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?
#1
Script,
from tkinter import *

main = Tk()
main.title("1. Unit & Dimentions")
#root.geometry("1600x800+0+0")

#Var Details
length = ["meter", "m"]
mass = ["kilogram", "kg"]
time = ["second", "s"]
current = ["ampere", "A"]
temperature = ["kelvin", "K"]
amount_of_substance = ["mole", "mol"]
luminous_intensity = ["candela", "cd"]

Fundamentals = [length, mass, time, current, temperature, amount_of_substance, luminous_intensity]

#Text
name = Label(main, text = "1. Unit & Dimentions", font = ("arial", 45, "bold"), fg = "Steel Blue", bd = 10)
mj = Label(main, text = "A product of MihiraJ.com", font = ("arial", 26, "bold"), fg = "#cc5c54", bd = 10)
dev = Label(main, text = "Devloped by Oshadha Mihiranga", font = ("arial", 18, "bold"), fg = "Steel Blue", bd = 10)
search = Label(main, text = "Search", font = ("arial", 10, "bold"), fg = "black", bd = 10)

#Text boxes
search_box = Entry(main, borderwidth = 4, width = 34)

#Frames
results = LabelFrame(main, text = "Results")
rel_results = LabelFrame(main, text = "Related Results")

#errors
err001 = Label(results, text = "Err001 : Result not Found, Please type again.", fg = "#eb0000")

#functions
def no_input():
    err001.pack(padx = 6, pady = 6, side = LEFT)

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)

def search_start(txt_2_search):
    if txt_2_search == "":
        no_input()
    if txt_2_search == "mass":
        result_found("Mass", mass)


#buttons
search_button = Button(main, text = "Start Search", command = lambda : search_start(search_box.get().lower()))

#pack
name.pack()
mj.pack()
search.pack()
search_box.pack()
search_button.pack()
results.pack(fill = X)
dev.pack()

mainloop()
So basically, when I click search_button , it calls out the function search_start.
Now, and search start, calls out result_found or no_input
What I want to do, is delete result_lbl and then pack result_lbl again with new data.

I tried doing result_lbl.pack_forget()
but I can find where to put it!

If you don't understand this question, pls msg me.
And if I did something wrong, I'm really sorry. Im new to forums.
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