+ 6
How to close a temporary Tkinter Toplevel widget by press on a button, see attached code
I have a code example for a datepicker in Tkinter. The freeware program is taken from the web. The source is mentioned in the comment section at the beginning of the code. I have done some slight adaptions to the code to fit my needs. Now I have one big question: What do I have to do that the temporary datepicker window closes after having pressed one of the numbered buttons. I have no clue. Any help is appreciated. I must admit that I am not very experienced with this object oriented programming stuff, but i am willing to learn it. https://code.sololearn.com/cpv57guA2r7Y/?ref=app
8 odpowiedzi
+ 2
I have the solution of the problem:
When adding
self.destroy()
as the last line of the function get_date(self, clicked=None) outside of the try-except-block the datepicker-window closes as wanted.
I hope this complies with all written and unwritten rules ....
+ 2
AKSHAY Right, but it just looks like he has one top level (cause thats what tkinter allows) and a bunch of widgets in a couple of frames.
Jan Markus nice man. if that dont work, there is also a .grid_forget() function
+ 1
Slick
are you sure that this will work? The example is done with the grid-packer and not with the pack-packer.
I am still not clear with which call and where I can close the window. I have to relate a lot to an object. but what is the correct object name. I have already tried everything and I just don't know what to do next.
+ 1
Hide: root.withdraw()
Show: root.deiconify()
0
try using .pack_forget()
its like pack(), but for hiding instead of making visible
0
Jan Markus use variable_for_Toplevel. destroy
0
what exact widget are you trying to close? i see you have both frames packed in
0
Slick Toplevel windows can't be closed by pack_forget()