I am creating a UI in tk "python" and I have a problem with some methods. I can't remove or forget buttons, that means widgets that contain an image inside. The mistake is AttributeError: 'NoneType' object has no attribute 'grid_remove' ...yes, i use grid...
if you know a better form to creating nicer interfaces. I would appreciate it :) thanks.
from tkinter import *
#---------------------------------------------------------------
root = Tk()
root.title("Tienda Virtual")#Titulo de la ventana
#root.resizable(1,0) impedir el redimencionamiento
root.iconbitmap("iconoroot.ico")
root.geometry('650x452+500+200')
root.resizable(0,0)
root.config(bg="white")
#---------------------------------------------------------------
# Creating a function for removing widgets from grid
def remove(l):
for w in l:
w.grid_remove()
# Creating a function for making widget visible again
def display(widget1, widget2):
widget1.grid(column=0, row=3, padx=10, pady=10)
widget2.grid(column=0, row=4, padx=10, pady=10)
#------------------------------------------------------------------
fr = Frame(root)
fr.pack(expand=1, fill='both')
fr.config(bg="white")
fr.config(relief ="groove", bd=2)
fr2 = Frame(fr)#se puede especificar dentro de frame la root y el tamaño directamente acà
fr2.pack(expand=1, anchor="n")
#-------------------------------------------------------------------------------
frd1 = Frame(fr2)#se puede especificar dentro de frame la root y el tamaño directamente acà
frd1.config(bg="white")
frd1.grid(row=0, column=0, pady=50, padx=0)
frd2 = Frame(fr2)#se puede especificar dentro de frame la root y el tamaño directamente acà
frd2.config(bg="white")
frd2.grid(row=1, column=0, pady=0, padx=0)
#---------------------------------------------------------------------------------
titulo = Label(frd1,
text="Tienda Virtual",
fg = "#cc0000",
#bg = "ligth blue",
font =("Arial Black",35)).grid(row=0, column=2, pady=30, padx=60)
imag = PhotoImage(file = r"C:\Users\usuario\Desktop\Drive\ERP\carritocompras.png").subsample(7, 7)
a = Button(frd2, text = "Administracion", image = imag, compound = BOTTOM, height = 150, width =150).grid(row=0, column=1, pady=2, padx=5)
b1 = Button(frd2, text="Vinayak")
b1.grid(column=0, row=3, padx=10, pady=10)
# Label Widgets
l1 = Button(frd2, text="Rai")
l1.grid(column=0, row=4, padx=10, pady=10)
# Create and show button with remove() function
remove_btn = Button(frd2, text="Remove widgets",
command=lambda: remove([l1, b1, a]))
remove_btn.grid(column=0, row=0, padx=10, pady=10)
# Create and show button with display() function
display_btn = Button(frd2, text="Display widgets",
command=lambda: display(b1, l1))
display_btn.grid(column=0, row=1, padx=10, pady=10)
root.mainloop()
I need some way to clear the buttons to switch to another window. i hope understand. widgets