954,546 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

"replay" button for a GUI

Okay, I'm putting the finishing touches on a program I made that would simulate the game of Roulette at a casino, and I've run into a small problem.

Once the player runs out of money, I have a "game over" window that appears to notify them that they are now broke.

In this "Game Over" window, I wanted to:
a) Have a 'close' button, which would close both windows (the game over window AND the actual game interface)
b) Have a 'replay' button which would essentially reset the game, possibly by closing the original window and opening a new one altogether

I tried to implement this idea with this code:

def endGame(root):
        def play():
            curr = CurrentFunds()
            root.destroy()

        def stop():
            root.destroy()

        endLabel = Label(root, text = "I'm sorry, you have run out of money. \n" \
                         "Better luck next time!")
        endLabel.pack()
        
        closeButton = Button(root, text = 'Close')
        closeButton.config(command = stop)
        closeButton.pack(side=BOTTOM)

        retryButton = Button(root, text = 'Play Again?')
        retryButton.config(command = play)
        retryButton.pack(side=BOTTOM)


The problem is, I don't know how I would go about closing both windows, and also, if they clicked the replay button, I'm unsure of how to reopen the game.

The code above is located outside of the main function in my program, and if you want to take a look at what the program as a whole looks like, there's a link to another topic that I posted it in: http://www.daniweb.com/forums/thread99499.html

The code in that topic is 700 lines long though, so you might want to spare yourself the headache if you can. It is also unfinished, and I would advise against running it, as in the state it's in, it is an infinite loop.

Tetch
Newbie Poster
5 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You