0

I am making a little program. I made a frame and a label with some text that appear after clicking a button. That's all right. Now i want to make a button that say's something like "back" or "close" wich closes that frame and it's label.

What i want to close:
![image]: https://i.stack.imgur.com/wZm1G.jpg

How to look after i close that frame and it's label:

![image]: https://i.stack.imgur.com/QwXK4.jpg

I've tried some code like: frame.after(2000, lambda: frame.destroy()) but it doesn't work. I've tried more, but again.. it doesn't work.

def inceput():
global windows3
windows3 = Tk()
windows3.title("EasyQuizy v1.0")
windows3.geometry("600x600+600+200")
windows3.resizable(False, False)
windows3.configure(bg="#472025")

headerFrame = Frame(windows3, width=("100"), height=("0")).pack(side=TOP)
frameLeft = Frame(windows3, width="100", height="600", bg="#7b8781").place(x=0, y=0)
frameRight = Frame(windows3, width="100", height="600", bg="#7b8781").place(x=500, y=0)
header = Label(headerFrame, width=("100"), height=("3"), bg="#9d7448", fg="#d9ab33", borderwidth=1, relief="solid",
               font="Helvetica 14 bold italic", text=("Bine ai venit, " + str(numeUtilizator.get()) + '!')).pack()

butonRights = Button(frameLeft, width=("9"), height=("2"), text="Drepturi de \nautor", bg="#6ab891", fg="#131313",
                     font="arial 8 bold", borderwidth=4, relief="raised", command = drepturi_autor)
butonRights.place(x=7, y=100)

butonInfo = Button(frameLeft, width=("9"), height=("2"), text="Imbunatatiri", bg="#6ab891", fg="#131313",
                   font="arial 8 bold", borderwidth=4, relief="raised")
butonInfo.place(x=7, y=180)
windows3.mainloop()





def drepturi_autor():
global frame
frame = Frame(windows3, highlightbackground="black", highlightcolor="black", highlightthickness=2, width=(390), height=(150), bg="#afd5c1").place(x=105, y=90)
label1 = Label(frame,text="EasyQuizy este o aplicatie\ncreata de mine pentru tine.", bg="#82ac96", fg="#f2f2f2", font="arial 14 bold italic").place(x=152, y=102)
frame.after(2000, frame.destroy)
  • 1
    `frame.after(2000, lambda: frame.destroy())` though overkill it should still work. Try doing `frame.after(2000, frame.destroy)`. However with the example you gave there is not enough code here to be sure of what is going on. – Mike - SMT Dec 27 '18 at 15:33
  • It doesn't work with frame.after(2000, frame.destroy) It says: AttributeError: 'NoneType' object has no attribute 'after' I will put more code up there. – Tony Moldovan Dec 27 '18 at 15:52
  • 2
    @TonyMoldovan You are creating the widgets and calling ```place``` on the same line which return None. Creation of the widget and placement of the widgets need to be on two different lines. – Joshua Nixon Dec 27 '18 at 15:54
  • @JoshuaNixon Ah yep that would do it. I guess I should have scrolled over to look at the OP's code more closely. Adding to what TonyMoldovan said. You need to always use your geometry manager on a new line after building your containers. If you do not then you will not be able to assign widgets to the container nor will you be able to directly destroy that container or do anything to it. That said you will also need to use your geometry managers on new lines for other widgets if you plan on editing them later in your code. – Mike - SMT Dec 27 '18 at 15:55
  • @Mike-SMT, I always check it first as I used to make the same mistake when learning tkinter! – Joshua Nixon Dec 27 '18 at 15:56
  • @JoshuaNixon I believe that is it. You should add your comment as an answer. – r.ook Dec 27 '18 at 16:02
  • @JoshuaNixon that was it, man. I'm home now and i've tried it. It works :) Thank you! Have a nice day! – Tony Moldovan Dec 27 '18 at 20:48

1 Answers1

-1

try so

from tkinter import *

windows3 = Tk()
windows3.title("EasyQuizy v1.0")
windows3.geometry("600x600+600+200")
windows3.resizable(False, False)
windows3.configure(bg="#472025")

def drepturi_autor():
    frame = Frame(windows3, highlightbackground="black", highlightcolor="black", highlightthickness=2, width=(390), height=(150), bg="#afd5c1")
    frame.pack()
    label1 = Label(frame,text="EasyQuizy este o aplicatie\ncreata de mine pentru tine.", bg="#82ac96", fg="#f2f2f2", font="arial 14 bold italic").place(x=100, y=52)
    frame.after(2000, frame.destroy)

headerFrame = Frame(windows3, width=("100"), height=("0")).pack(side=TOP)
frameLeft = Frame(windows3, width="100", height="600", bg="#7b8781").place(x=0, y=0)
frameRight = Frame(windows3, width="100", height="600", bg="#7b8781").place(x=500, y=0)
header = Label(headerFrame, width=("100"), height=("3"), bg="#9d7448", fg="#d9ab33", borderwidth=1, relief="solid",
               font="Helvetica 14 bold italic", text=('Bine ai venit!')).pack()

butonRights = Button(frameLeft, width=("9"), height=("2"), text="Drepturi de \nautor", bg="#6ab891", fg="#131313",
                     font="arial 8 bold", borderwidth=4, relief="raised", command = drepturi_autor)
butonRights.place(x=7, y=100)


windows3.mainloop()
patel
  • 430
  • 1
  • 4
  • 9