Re-execute main program

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Apr 2009
Posts: 29
Reputation: txwooley is an unknown quantity at this point 
Solved Threads: 3
txwooley txwooley is offline Offline
Light Poster

Re-execute main program

 
0
  #1
Jun 23rd, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 686
Reputation: sillyboy is on a distinguished road 
Solved Threads: 61
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

Re: Re-execute main program

 
1
  #2
Jun 23rd, 2009
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".
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 29
Reputation: txwooley is an unknown quantity at this point 
Solved Threads: 3
txwooley txwooley is offline Offline
Light Poster

Re: Re-execute main program

 
0
  #3
Jun 23rd, 2009
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!
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 686
Reputation: sillyboy is on a distinguished road 
Solved Threads: 61
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

Re: Re-execute main program

 
0
  #4
Jun 23rd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 489
Reputation: shadwickman will become famous soon enough shadwickman will become famous soon enough 
Solved Threads: 76
shadwickman's Avatar
shadwickman shadwickman is offline Offline
Posting Pro in Training

Re: Re-execute main program

 
0
  #5
Jun 23rd, 2009
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.
"Two good old boys in a fire-apple red convertible. Stoned. Ripped. Twisted. Good people."
- Hunter S. Thompson

my photography
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 29
Reputation: txwooley is an unknown quantity at this point 
Solved Threads: 3
txwooley txwooley is offline Offline
Light Poster

Re: Re-execute main program

 
0
  #6
Jun 24th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 489
Reputation: shadwickman will become famous soon enough shadwickman will become famous soon enough 
Solved Threads: 76
shadwickman's Avatar
shadwickman shadwickman is offline Offline
Posting Pro in Training

Re: Re-execute main program

 
1
  #7
Jun 24th, 2009
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!
"Two good old boys in a fire-apple red convertible. Stoned. Ripped. Twisted. Good people."
- Hunter S. Thompson

my photography
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 29
Reputation: txwooley is an unknown quantity at this point 
Solved Threads: 3
txwooley txwooley is offline Offline
Light Poster

Re: Re-execute main program

 
0
  #8
Jun 24th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC