Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting a Label in Python Tkinter?

I am trying to hide everything in this function:

def addHome(self):
    Label(self, text = "Would you like to add to your to-do list, or generate a random item?", bg="#efefef").grid(row = 3, columnspan = 2, sticky="W")
    self.txtHome = Entry(self)

    self.btnAddToIt = Button(self, text = "Add To It!", bg="#efefef")
    self.btnAddToIt.grid(row = 4, columnspan = 2)
    self.btnAddToIt["command"] = self.addToIt

    self.btnRandom = Button(self, text = "Random!", bg="#efefef")
    self.btnRandom.grid(row = 5, columnspan = 2)
    self.btnRandom["command"] = self.addRandom

So that I can show the things in these functions:

def addToIt(self):
    #self.clearMiddle()
    Label(self, text = "Add To List").grid(row = 3, columnspan = 2)
    self.addInput()

    self.btnProcessAdd = Button(self, text = "Add To It!", bg="#efefef")
    self.btnProcessAdd.grid(row = 7, column = 0)
    self.btnProcessAdd["command"] = self.processAdd

    self.btnCancel = Button(self, text = "Cancel", bg="#efefef")
    self.btnCancel.grid(row = 7, column = 1)
    self.btnCancel["command"] = self.addHome

def addInput(self):
    #adds input for add to item page
    Label(self, text = "Name of Item:", bg="#efefef", width=50).grid(row=3, column=0)
    self.nameOfItem = Entry(self)
    self.nameOfItem.grid(row = 3, column = 1)
    self.nameOfItem.insert(0, "Be Awesome")

    Label(self, text = "Item Category:", bg="#efefef", width=50).grid(row = 4, column = 0, sticky="E")
    self.itemCategory = Listbox(self, height = 5)
    self.itemCategory.grid(row = 4, column = 1)
    self.itemCategory.insert(END, "Fun", "School", "Work", "Exercise", "Other")

    Label(self, text = "Other Item Details:", bg="#efefef", width=50).grid(row = 5, column = 0, sticky="E")
    self.otherItemDetails = Text(self, width=22, height=3)
    self.otherItemDetails.grid(row = 5, column = 1)

    Label(self, text = "Due Date (mm/dd/yy):", bg="#efefef", width=50).grid(row = 6, column = 0, sticky="E")
    self.dueDate = Entry(self)
    self.dueDate.grid(row = 6, column = 1)
    self.dueDate.insert(0, "06/19/2013")

Then vice versa when the Cancel button is hit (clearing the things in addToIt and addInput). Is there any way I can do this?

like image 819
Rachelle Bennington Avatar asked Jun 19 '13 17:06

Rachelle Bennington


People also ask

How do I drop a label in Python?

DataFrame - drop() functionThe drop() function is used to drop specified labels from rows or columns. Remove rows or columns by specifying label names and corresponding axis, or by specifying directly index or column names. When using a multi-index, labels on different levels can be removed by specifying the level.

How do you destroy labels?

You can easily remove by first covering the label with a piece of paper doubled or a hand towel. Heat up your iron(not too hot now)and go over the covered label a few times. The adhesive is loosened and voila! Off comes the label when pulled from the loosened corner.

Can you change the text of a label in tkinter?

Tkinter Label widgets are commonly used in applications to show text or images. You can change the label widget's text property, color, background, and foreground colors using different methods. You can update the text of the label widget using a button and a function if you need to tweak or change it dynamically.

How do you delete a text box in Python?

Type something inside the textbox, and then, click the “Delete” button. It will erase the content inside the textbox.


1 Answers

Yes, there is some way. I see you are using grid. So, to hide an object use Object.grid_forget(). Just in case, if you use pack, you can hide an object by Object.pack_forget(). Same thing works with place.

I have some idea, that might come in handy. I recommend you to have all objects you want to hide simultaneously in a single Frame, so you will just use Frame.grid_forget() instead of

Obj1.grid_forget()
Obj2.grid_forget()
Obj3.grid_forget()
.
.
.

Remember that using this will only make any object invisible, but it still exists "within" memory with all its properties.

like image 84
Milan Skála Avatar answered Sep 30 '22 15:09

Milan Skála