Python tkinter, restart the program
Question: this is simple example of my code:

    
    
    from tkinter import *
    import random
    
    
    class A:
    
        def __init__(self, master):
            n = random.randrange(1, 10, 1)
            self.frame_a = Frame(master)
            self.frame_a.pack()
            self.label_a = Label(self.frame_a, text=n)
            self.label_a.pack()
    
        def clean(self):
            self.frame_a.destroy()
            A(root)
            B(root)
    
    
    class B:
    
        def __init__(self, master):
            self.frame_b = Frame(master)
            self.frame_b.pack()
            self.button_b = Button(self.frame_b, text='again', command=self.do_again)
            self.button_b.pack()
    
        def do_again(self):
            self.frame_b.destroy()
            hello.clean()
    
    
    root = Tk()
    hello = A(root)
    world = B(root)
    root.mainloop()
    

I want delete all frames and label and restart the program. But it doesn't
work correctly. When I first time use button `again`, it works. However If I
click button again, frame won't destroy.

EDIT: This is sample of my code:

    
    
    class GamePick:
    
        def __init__(self):
            #there are also some labels and frames but they relate to my problem
    
        def do_black_jack(self):
            global bj
            global bj_play
            ''' You pick Black Jack, open new window and close actual window'''
            bj = Toplevel(self.master)
            bj_play = BjGui(bj)
            bj['bg'] = 'springgreen4'
            bj.wm_geometry("1500x900")
            Choices.close(my)
    
    class BlackJack:
    
       #There are some function for pick new card for player and dealer
    
        def check_limit(self):#
            if sum(player_cards_val) > 21:
                if 11 in player_cards_val:
                        player_cards_val.remove(11)
                        player_cards_val.append(1)
                        self.check_limit()
                else:
                        bj_play.show_result(res='Dealer win')
            elif sum(bot_cards_val) > 21:
                if 11 in bot_cards_val:
                        bot_cards_val.remove(11)
                        bot_cards_val.append(1)
                        self.check_sixteen()
                else:
                        bj_play.show_result(res='Player win')
            else:
                if sum(player_cards_val) > sum(bot_cards_val):
                        bj_play.show_result(res='Player win')
                else:
                        bj_play.show_result(res='Dealer win')
    
    
    
    class BjGui:
    
    
        def __init__(self, master):
            self.master = master
            self.bot_frame = Frame(self.master, height=False, width=False, bg='springgreen4')
            bj.wm_geometry("1500x900")
            self.bot_frame.pack(side='top', pady=20)
            self.player_frame = Frame(self.master, height=False, width=False, bg='springgreen4')
            bj.wm_geometry("1500x900")
            self.player_frame.pack(side='bottom', pady=20)
            self.buttons_frame = Frame(self.master, bg='springgreen4')
            self.buttons_frame.pack(side=BOTTOM)
            # There are function for this class, they show players cards and bots cards from class Black Jack
    
    
        def show_result(self, res):#This function, create new label and button.
                                   #  New label show result of the game, after I click button, it should will restart 
            self.info_label = Label(self.master, text=res, font=('aharoni', 60), bg='springgreen4', pady=35)
            self.info_label.pack()
            self.again_frame = Frame(self.master)
            self.again_frame.pack()
            self.again_bt = Button(self.again_frame, text='play again', font=('times', 12), command=self.do_again, bg='blue')
            self.again_bt.pack()
    
        def do_again(self):# This should delete all frames and clear list with cards and restart game, but it doesn't work
            self.info_label.destroy()
            self.again_frame.destroy()
            self.player_frame.destroy()
            self.bot_frame.destroy()
            self.buttons_frame.destroy()
            bot_cards_key.clear()
            bot_cards_val.clear()
            player_cards_key.clear()
            player_cards_val.clear()
            no_repeat.clear()
            BlackJack()
            BjGui(bj)
    

I would like to create Black Jack game. `class BlackJack` picks new cards for
player and dealer, compare value of these cards, and determite who is winner.
`class BjGui` shows players and dealers cards, there some buttons frames and
labels. When the game ends, I use function `check_limit`, it determites who is
winner and function `show_result` create new label with result and new button.
This button should be able restart the game.


Answer: I don't think you want the object recursion that you have. You're making new
`A`s and `B`s inside the current `A` that you're working with - the top of the
stack. `hello` and `world` only refer to the bottom of the stack, not to all
the other `A`s and `B`s in your object recursion stack.

Also, I'm not sure why you want two different classes or two different frames.
I would have to understand what you want to give a suggestion on how to do it
with different frames and classes.

    
    
    from tkinter import *
    import random
    
    
    class A:
        def __init__(self):
            self.master = Tk()
    
            self.frame_a = None
            self.label_a = None  # not necessary, but common styling preference
            self.button_b = None  # not necessary, but common styling preference
    
            self.clean()
            self.master.mainloop()
    
        def clean(self):
            if self.frame_a is not None:
                self.frame_a.destroy()
            n = random.randrange(1, 10, 1)
            self.frame_a = Frame(self.master)
            self.frame_a.pack()
            self.label_a = Label(self.frame_a, text=n)
            self.label_a.pack()
            self.button_b = Button(self.frame_a, text='again', command=self.clean)
            self.button_b.pack()
    
    
    hello = A()
    

