Mar-01-2018, 05:54 PM
It is the simple program, where I tried to make the Frame widget clear for me, but something went wrong. When I start the program:
I wish the whole program to start with a one red square and two buttons. Pressing "Delete" button will cause the deleting of the Frame widget(it works, I think, because I used
I will appreciate any help, thanks.
P.S. I just new in Python, so have such stupid questions.
from tkinter import * root = Tk() root.geometry("500x500") def new(): global ss ss = Frame(root, height=200, width=200, bg="red") ss.pack() clean = Button(root, text="Delete", command=lambda: ss.destroy()) clean.pack() add = Button(root, text="Add", command=new()) add.pack() ss = Frame(root, height=200, width=200, bg="red") ss.pack() root.mainloop()it makes the window with 2 red squares and 2 buttons. But the location of all this things is rather strange. Button, then square, then another button and the last square. I think it is about using
pack()
.I wish the whole program to start with a one red square and two buttons. Pressing "Delete" button will cause the deleting of the Frame widget(it works, I think, because I used
lambda
), pressing "Add" button has to cause the creating of the same Frame that we just deleted. But it does not. Pressing this button has no effect on program.I will appreciate any help, thanks.
P.S. I just new in Python, so have such stupid questions.