Please support our Python advertiser: Programming Forums
![]() |
I had that problem a few days ago about running external python programs, which I know know can be done with
But I now have a new problem....
Here is my program I am making for myself:
When I run it, it does exactly what it's supposed to do, however I would like it to make a new choice if
And I would like for there to be a half second delay when it shows the game, as if it were taking to decide the game, and then taking another half second to decide if it's approved or not.
Another thing I would like, but can't figure out either, is I want to start button's text to change to "Restart" from "Start" once it's been pressed once.
Thanks for your time and help guys...
execfile("filename.py")But I now have a new problem....
Here is my program I am making for myself:
import random
from Tkinter import *
mainWindow = Tk()
strGame=""
def dieSimulator():
number = random.randint(1,6)
if number == 1:
#print "UNO"
strGame = "UNO"
answerLabel.configure(text=strGame)
elif number == 2:
#print "SMASH TV"
strGame = "SMASH TV"
answerLabel.configure(text=strGame)
elif number == 3:
#print "HALO"
strGame = "HALO"
answerLabel.configure(text=strGame)
elif number == 4:
#print "PDZ"
strGame = "PDZ"
answerLabel.configure(text=strGame)
elif number == 5:
#print "COD"
strGame = "COD"
answerLabel.configure(text=strGame)
elif number == 6:
#print "GRAW"
strGame = "GRAW"
answerLabel.configure(text=strGame)
number2 = random.randint(1,2)
restart = dieSimulator
if number2 == 1:
strGame2 = "Approved"
answerLabel2.configure(text=strGame2)
elif number2 == 2:
strGame2 = "Denied"
answerLabel2.configure(text=strGame2)
startButton = Button(mainWindow, text="Start", command=dieSimulator)
startButton.grid(row=0, column=0)
answerLabel = Label(mainWindow, text="Game...")
answerLabel.grid(row=0, column=1)
answerLabel2 = Label(mainWindow, text="Approved/Denied...")
answerLabel2.grid(row=1, column=1)
mainloop()When I run it, it does exactly what it's supposed to do, however I would like it to make a new choice if
strGame2 = "Denied"
And I would like for there to be a half second delay when it shows the game, as if it were taking to decide the game, and then taking another half second to decide if it's approved or not.
Another thing I would like, but can't figure out either, is I want to start button's text to change to "Restart" from "Start" once it's been pressed once.
Thanks for your time and help guys...
I want it to be exactly like this
But to run entirely in a window with a start button...
#Dedicated to Defender117's "Die of Decision" and "coin of choice"....
# [version 1.8]
print " "
import random
import time
strGame = 0
number = random.randint(1,6)
if number == 1:
print "UNO"
strGame = "UNO"
elif number == 2:
print "SMASH TV"
strGame = "SMASH TV"
elif number == 3:
print "HALO"
strGame = "HALO"
elif number == 4:
print "PDZ"
strGame = "PDZ"
elif number == 5:
print "COD"
strGame = "COD"
elif number == 6:
print "GRAW"
strGame = "GRAW"
number2 = random.randint(1,2)
if number2 == 1:
time.sleep(0.5)
print "approved\n"
vetoIt = raw_input("Veto It?" )
if vetoIt == "y":
execfile("die of decision simulator.py")
if vetoIt == "n":
print "Then the decision stands:",strGame
elif number2 == 2:
time.sleep(0.5)
print "denied"
time.sleep(0.5)
execfile("die of decision simulator.py")
But to run entirely in a window with a start button...
Last edited by Matt Tacular : Jun 13th, 2006 at 1:36 am.
Well, I can help with the startButton text:
def dieSimulator():
startButton.configure(text="Restart")
# rest of your code .......•
•
Join Date: Aug 2005
Location: England - York
Posts: 136
Reputation:
Rep Power: 4
Solved Threads: 9
the half a second delay can be done either using:
that would be the simplest however the whole code including the GUI would hang as if it crashed, so a slightly more complicated method is doing a while loop, checking the time on each pass, and if it is more than half a second, exiting the loop, and continuing, which is done with the following code:
Just whack the above function into your code then whenever you want a time delay, just put Delay(0.5) into your code, and it should work
happy coding,
a1eio
import time time.sleep(0.5)
from time import time
def Delay(delay):
stopTime = time()+delay
while time() < stopTime:
pass
returnJust whack the above function into your code then whenever you want a time delay, just put Delay(0.5) into your code, and it should work
happy coding,
a1eio
•
•
Join Date: Aug 2005
Location: England - York
Posts: 136
Reputation:
Rep Power: 4
Solved Threads: 9
the program will pick a game, and then pick either approved or denied. what i want it to do is start over - pick a new game, if it gets denied.
This program is a simple simulator for a dice, which has written on the 6 sides, different games, you roll the dice, and then you flip the coin, heads is yes, tails is no, if it lands on tails, you roll the dice again, untill you get one that gets heads (approved)
So i was doing this for a friend of mine. I was able to make one that is text based, the code is in post #2. But I wanted to do it all in a window.
So, my objective was to make a window with a single button "start". that when pressed, there would be a delay of about a half second, then it shows the game it picked, then another delay, and it shows wether or not that choice is approved or denied. If denied, there is another delay, then shows a new game choice, and so on and so on until one that gets approved.
I havent tried to use the delay thing from post #5 yet, but if I can implement it right, then all i need it to do is restart if denied is chosen.
And the veto it thing is something my friend kept saying, about using your veto powers to change the choice, in other words, restart...
In case you were wondering: http://en.wikipedia.org/wiki/Veto
This program is a simple simulator for a dice, which has written on the 6 sides, different games, you roll the dice, and then you flip the coin, heads is yes, tails is no, if it lands on tails, you roll the dice again, untill you get one that gets heads (approved)
So i was doing this for a friend of mine. I was able to make one that is text based, the code is in post #2. But I wanted to do it all in a window.
So, my objective was to make a window with a single button "start". that when pressed, there would be a delay of about a half second, then it shows the game it picked, then another delay, and it shows wether or not that choice is approved or denied. If denied, there is another delay, then shows a new game choice, and so on and so on until one that gets approved.
I havent tried to use the delay thing from post #5 yet, but if I can implement it right, then all i need it to do is restart if denied is chosen.
And the veto it thing is something my friend kept saying, about using your veto powers to change the choice, in other words, restart...
In case you were wondering: http://en.wikipedia.org/wiki/Veto
Last edited by Matt Tacular : Jun 14th, 2006 at 12:22 pm.
•
•
Join Date: Aug 2005
Location: England - York
Posts: 136
Reputation:
Rep Power: 4
Solved Threads: 9
Here's my version, slightly adapted, there's probably some new stuff in there if your new to making gui's but just ask about what you might not recognise and i'll explain, it's all pretty simple really
import random
from Tkinter import *
from time import time
def sleep(delay):
stopTime = time()+delay
while time() < stopTime:
mainWindow.update()
return
def clear():
answerLabel.configure(text="")
answerLabel2.configure(text="")
mainWindow.update()
def dieSimulator():
denied = True
startButton.configure(text="Restart")
while denied:
sleep(2)
number = random.randint(1,6)
clear()
if number == 1:
#print "UNO"
strGame = "UNO"
answerLabel.configure(text=strGame)
elif number == 2:
#print "SMASH TV"
strGame = "SMASH TV"
answerLabel.configure(text=strGame)
elif number == 3:
#print "HALO"
strGame = "HALO"
answerLabel.configure(text=strGame)
elif number == 4:
#print "PDZ"
strGame = "PDZ"
answerLabel.configure(text=strGame)
elif number == 5:
#print "COD"
strGame = "COD"
answerLabel.configure(text=strGame)
elif number == 6:
#print "GRAW"
strGame = "GRAW"
answerLabel.configure(text=strGame)
mainWindow.update()
number2 = random.randint(1,2)
restart = dieSimulator
sleep(2)
if number2 == 1:
strGame2 = "Approved"
answerLabel2.configure(text=strGame2)
denied = False
elif number2 == 2:
strGame2 = "Denied"
answerLabel2.configure(text=strGame2)
denied = True
mainWindow.update()
startButton.configure(text = "start")
mainWindow = Tk()
startButton = Button(mainWindow, text="Start", command=dieSimulator, width=20)
startButton.grid(row=0, column=0)
answerLabel = Label(mainWindow, text="Game...", width=20)
answerLabel.grid(row=0, column=1)
answerLabel2 = Label(mainWindow, text="Approved/Denied...", width=20)
answerLabel2.grid(row=1, column=1)
mainWindow.mainloop() I understood most of what you did and how it works, and the way I learn to program is by analysing why other programs can do what they do, and try to incorporate it. And if I can't find a program that does it, I ask for help, and I recently came across these forums, nothing to find here but loads of help 
Thanks guys, and the program does EXACTLY what it is I wanted. Thanks a bunch.

Thanks guys, and the program does EXACTLY what it is I wanted. Thanks a bunch.
![]() |
Similar Threads
Other Threads in the Python Forum
- python extending with c(doubts) (Python)
- reading from a file with python (Python)
- mandelbrot generator messed up (Python)
Other Threads in the Python Forum
- Previous Thread: Call to Module Won't Refresh
- Next Thread: animated image
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode