0

I am trying to make a number guesser in python 2.7 with Tkinter. I am having trouble on making the MessageBox disappear after I hit ok.

import random
import Tkinter 
import tkMessageBox
import tkSimpleDialog


root = Tkinter.Tk() 

Random_Pick = random.randint(1,10)
No_Tries = 0
G = True
while G == True: 
    print  ('Guess A Number!')
    Guess = tkSimpleDialog.askinteger('Game', 'Pick A Number Between 1 And 10:')
    print Guess
    if Guess is not None:
        Guess = int(Guess)
        Q = True
    if Guess is None:
        pass
    while Q == True:
        if Guess != Random_Pick:
            Sorry = tkMessageBox.showinfo ('Sorry', 'You Got It Wrong.')
            No_Tries = No_Tries + 1

        if Guess == Random_Pick:
            No_Tries = str(No_Tries)
            if No_Tries == str(1):
                OneTry = tkMessageBox.showinfo ('Congratulations!', 'You Got It Right! It took ' + No_Tries + ' Try!' )
                print OneTry
            else: Tries= tkMessageBox.showinfo ('Congratulations!', 'You Got It Right! It took ' + No_Tries + ' Tries!')
            print Tries
            G = False
        while No_Tries == 3:
            Random_Pick = str(Random_Pick)
            tkMessageBox.showinfo ('Sorry', 'You Lose. The Number was ' + Random_Pick)
            No_Tries = 0
            G = False                      

if AttributeError:
    pass

root.mainloop()

I am not sure why the MessageBox Does't disappear after I click ok. Is there anyway to make that happen with Tkinter?

Artemis
  • 2,553
  • 7
  • 21
  • 36

1 Answers1

0

The inner while loop has no exit. It loops on the condition Q == True but nothing inside the loop modifies Q.

figbeam
  • 7,001
  • 2
  • 12
  • 18