I have written a poker game in Python and have it fairly well finished. My hang-up now is an option to play again. Most of the game is in a function called playHand() which re-runs as long as you still have money, but if you lose all of your money, or the computer characters all lose theirs, I want to give an option to 'play again'. This would require basically re-running the entire program from the beginning. I have seen others use something like "if name == __main__:" but I'm not sure how that works or if that is what I need. How do I re-start the entire program so you could re-play the game as if you just started it?

Recommended Answers

All 7 Replies

just move the entry/start point of your game into a function, and then at the end of that function (even after) you can give the use the option to "play again".

commented: Thanks +1

OK. That almost sounds TOO simple. I kick myself for not thinking of this. Thanks. On the same program but a different topic, this is currently a text based game. I have been teaching myself Python via on-line tutorials for about the last year now and think I might be ready to attempt GUI. Which would be the best for me to use for a Texas Hold 'Em card game? I use exclusively Linux OS and don't care if it runs on Doze or not. Can anyone point me at the best GUI to use and perhaps recommend some on-line tutorials? Thanks for the input, and thanks again for answering my stupid question about main. I feel silly now! I have been trying to figure this out for almost two weeks!

it's ususally the simple "bugs/fixes" that are the hardest to see because they are simply overlooked. good luck with the GUI, unfortunately i haven't dealt with python GUIs before, but i'm sure somebody around here will be able to help.

As for a regular application, I'd go with wxPython for sure. Best GUI toolkit I've used for Python (I can't stand Tkinter at all).
If you want to make it more graphics-rich and not look like a regular program, you can try pygame, but that might be a bit difficult to jump into right away.

Thanks shadwickman. I thought wxPython was a Windows application. I just get that from the name though. I will look into it. Thanks. I see a tutorial on this site, but can you recommend another on-line or perhaps even a book to purchase for a relatively new python guy?

Which Linux distro are you using? Regardless, if you want a visual editor for wxPython, I'd suggest wxGlade. It generates nice code but it may take a little getting used to using. I mostly just code all my GUIs by hand anyways.
As for good wxPython resources, here's some:

Style Guide - Not too comprehensive, but might offer some standardizing tips.
wxPython by Example - A short tutorial which has good examples for bare-bones apps.
wxPython Cookbook - Contains a lot of information on various aspects of wxPython. Lots of examples.
Widget Examples - Has a number of good application skeletons and examples about individual widgets and their uses.
Documentation - The regular documentation for wxPython.

VERY GOOD Tutorial - I'd recommend giving this a read through and looking at the example code as it's quite large and it covers a lot in an understandable way.

wxGlade Tutorial - If you decide to give wxGlade a go. Make sure to learn pure wxPython coding first so that you can do it by hand. Then use this for large GUIs just to speed things up if you want.

There was another very definitive page with all the widgets and examples and information about them, but I can't seem to find it at the moment. I'll post it later if I do find it. Hope these help for now! :)

Hey, thanks again shadwickman. I was introduced to Ubuntu a few years ago and now I wont use anything else. These tutorials are just what I was looking for. Now I have my studying and reading cut out for me for the next few weeks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.