Pues intento modificar el texto de un label llamado "inf" desde un método llamado "get_information" y me sale error, intente con la función "configure" y me sigue saliendo error, como seria la manera correcta de modificarlo?
Con la funcion "configure" me sale este error:
Traceback (most recent call last):
File "rrr.py", line 110, in <module>
r = SystemAppleCore()
File "rrr.py", line 31, in __init__
self.get_information()
File "rrr.py", line 40, in get_information
inf.configure(text = "Database not generated")
NameError: name 'inf' is not defined
Y Cuando intento modificarla normalmente me sale este error:
typeerror: 'nonetype' object does not support item assignmen
t
Codigo | Python3:
class SystemAppleCore():
def __init__(self):
self.root = Tk()
self.root.title("Home Schoolers")
self.database = {}
self.tell = 0
Label(self.root, text = "Home Schoolers", font=("Comic Sans MS" ,15)).grid(row = 0, column = 0, sticky = W, pady = 10, padx = 5)
# Frame
frame = LabelFrame(self.root, text = " Menu of options ", font=("Comic Sans MS" ,12))
frame.grid(row = 1, column = 0, padx = 5)
# Frame Inf
self.frameMessage = LabelFrame(self.root, text = " Information ", font=("Comic Sans MS" ,12))
self.frameMessage.grid(row = 2, column = 0, pady = 8, padx = 5, sticky = W + E)
inf = Label(self.frameMessage, text = "").grid(row = 0, column = 0, pady = 5, padx = 5)
# Buttons
Button(frame, text = "Options of AppleCores", command = self.optionsAppleCores).grid(row = 0, column = 0, sticky = W + E, pady = 3, padx = 5)
Button(frame, text = "Create AppleCore", command = self.createAppleCore).grid(row = 1, column = 0, sticky = W +E, pady = 3, padx = 5)
Button(frame, text = "Exit", command = lambda:self.root.destroy()).grid(row = 2, column = 0, sticky = W +E, pady = 3, padx = 5)
self.get_information()
self.root.mainloop()
def get_information(self):
try:
open("AppleCoreDatabase", "rb").close()
inf["text"] = "Generated database"
except:
inf.configure(text = "Database not generated")
def accessAppleCore(self):
pass
def createAppleCore(self):
window = Toplevel()
window.resizable(False, False)
text = StringVar()
frame = LabelFrame(window, text = " Create AppleCore ", font=("Comic Sans MS" ,12))
frame.grid(row = 0, column = 0, pady = 10, padx = 10)
# AppleCore input
Label(frame, text = "Name-AppleCore:").grid(row = 0, column = 0, pady = 7, padx = 4)
name = Entry(frame, textvariable = text).grid(row = 0, column = 1, pady = 7, padx = 4)
# Message
# message = Label(window, text = "dawda").grid(row = 1, column = 0, sticky = W + E)
def create(name_AppleCore):
try:
with open("AppleCoreDatabase", "rb") as file:
self.database = pickle.load(file)
except:
pass
if name_AppleCore != "":
self.database[name_AppleCore] = {
"Notes": [],
"Assistance": []
}
with open("AppleCoreDatabase", "wb") as file:
pickle.dump(self.database, file)
window.destroy()
self.get_information()
else:
# message["text"] = "| Name-AppleCore is required |"
pass
# Button
Button(frame, text = "Add AppleCore", command = lambda:create(text.get())).grid(row = 2, column = 0, columnspan = 2, sticky = W + E)
def optionsAppleCores(self):
try:
with open("AppleCoreDatabase", "rb") as file:
self.database = pickle.load(file)
window = Toplevel()
window.resizable(False, False)
frame = LabelFrame(window, text = " AppleCores ", font=("Comic Sans MS" ,12))
frame.grid(row = 1, column = 1, padx = 5)
for appleCore in self.database.keys():
self.tell += 1
Checkbutton(frame, text = "AppleCore: " + appleCore, font=("Comic Sans MS" ,12)).grid(row = self.tell, column = 0, pady = 3, padx = 5, sticky = W)
except:
pass # mensaje aquiii
De antemano muchas gracias por sus respuestas!!