我試圖隱藏在這個函數中的一切:在Python Tkinter中刪除標籤?
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
所以,我可以顯示這些功能的東西:
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")
然後反之當取消按鈕被擊中(清除事在addToIt和addInput中)。有什麼辦法可以做到這一點?
是否要刪除窗口小部件或清除字段中的值? – FabienAndre
你可能會對這個其他線程感興趣:[在Tkinter有沒有什麼辦法讓widget不可見?](http://stackoverflow.com/questions/3819354)(特別是[Bryan的回答](http:// stackoverflow .com/a/5928294)) – FabienAndre
@FabienAndre我想刪除小部件。 –