+ 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

26th Jul 2020, 11:01 AM
Jan Markus
8 ответов
+ 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 ....
26th Jul 2020, 11:27 AM
Jan Markus
+ 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
26th Jul 2020, 11:28 AM
Slick
Slick - avatar
+ 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.
26th Jul 2020, 11:18 AM
Jan Markus
+ 1
Hide: root.withdraw() Show: root.deiconify()
16th Sep 2021, 6:25 PM
Sancho Godinho
Sancho Godinho - avatar
0
try using .pack_forget() its like pack(), but for hiding instead of making visible
26th Jul 2020, 11:09 AM
Slick
Slick - avatar
0
Jan Markus use variable_for_Toplevel. destroy
26th Jul 2020, 11:23 AM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar
0
what exact widget are you trying to close? i see you have both frames packed in
26th Jul 2020, 11:23 AM
Slick
Slick - avatar
0
Slick Toplevel windows can't be closed by pack_forget()
26th Jul 2020, 11:26 AM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar