outcomeG = "0"
outcomeB = "0"
def roll():
global outcomeG, outcomeB
outcomeG = random.randint(1, 6)
outcomeB = random.randint(1, 5)
def greenDiceRoll():
outcomeG = random.randint(1, 6)
outcomeB = random.randint(1, 5)
greenDiceOptions.destroy()
global greenDiceRoll
greenDiceRoll = tkinter.Tk()
greenDiceRoll.title("Good Dice roll")
lbloutcome = tkinter.Label(greenDiceRoll, text="Press roll")
btnRollG = tkinter.Button(greenDiceRoll, text="Roll", command=roll)
if outcomeG == "1":
lbloutcome.config(text="Green 1")
greenDiceRoll.update()
f = open("Logs.txt", "a")
ts = time.time()
sttime = datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d_%H:%M:%S - ')
f.write(sttime + "Green 1")
f.close()
elif outcomeG == "2":
lbloutcome.config(text="Green2")
greenDiceRoll.update()
f = open("Logs.txt", "a")
ts = time.time()
sttime = datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d_%H:%M:%S - ')
f.write(sttime + "Green 2")
f.close()
#rest of code
I am making a program that you can roll a red and a green dice. When you press the roll button the outcomeG and outcomeB do randomize a number. The problem is to do with the if statements, therefore the output doesn't go into the Logs.txt and the window isn't updated. Any help will be much appreciated.
Aucun commentaire:
Enregistrer un commentaire