I have a game, When a button is created, I need my program to just show this screen untill they press 'Next Level' all of this code is in a while loop so in a large while loop controlling the game.
......
if game.playerDistance >= game.lowerBound() and game.playerDistance <= game.upperBound():
game.level += 1
showLevelResults(game)
#NextLevelButton
btnNextLevel = Button(root,
#Random Config
command = nextLevel,
)
btnNextLevel.place(x=1003, y=492, anchor=NW, width=247, height=78)
updateMainScreen()
while nextLev == False:
#What Do I put in here to force a wait
else:
......
nextLev = False
def nextLevel():
nextLev = True
...
Currently this keeps it in the while loop and when the button is pressed nothing changes i have used time.sleep(1) to keep it waiting and also had it printing waiting for btn press, however this spams the console and when the button is pressed still doesnt change the screen.
def showGameSurvival():
game = gamemode_normal()
while game.health != 0:
game.next = False
clearScreen()
changeBackground("Survival")
#Placing Labels on the screen for game.....
#... Health
root.update()
lblCountDownLeft = Label(root, bg="White", fg="Green", font=XXLARGE_BUTTON_FONT)
lblCountDownLeft.place(x=169, y=350, anchor=CENTER)
lblCountDownRight = Label(root, bg="White", fg="Green", font=XXLARGE_BUTTON_FONT)
lblCountDownRight.place(x=1111, y=350, anchor=CENTER)
#CountDown
count = 7
while count > 0:
lblCountDownLeft['text'] = count
lblCountDownRight['text'] = count
root.update()
count -= 1
time.sleep(1)
lblCountDownLeft.destroy()
lblCountDownRight.destroy()
root.update()
#Num on left x=169, right, x=1111 y=360
game.measureDistance()
if game.playerDistance >= game.lowerBound() and game.playerDistance <= game.upperBound():
game.level += 1
clearScreen()
changeBackground("Survival")
graphicalDisplay(game)
#NextLevelButton
btnNextLevel = Button(root,
bg= lbBlue,
fg="white",
text="Level" + str(game.level),
font=SMALL_BUTTON_FONT,
activebackground="white",
activeforeground= lbBlue,
command= lambda: nextLevel(game),
bd=0)
btnNextLevel.place(x=1003, y=492, anchor=NW, width=247, height=78)
root.update()
while game.next == False:
print(game.next)
else:
game.health -= 1
if game.allowance > 4:
game.allowance = int(game.allowance*0.9)
#when game is over delete the shit
if game.health == 0:
del game
The next button now calls this function: def nextLevel(game):
game.next = True