我正在尝试使用Tkinter在python 2.7中创建一个数字猜测器。点击确定后,我无法让MessageBox消失。
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()
我不确定为什么单击确定后MessageBox不会消失。无论如何都要用Tkinter来实现这个目标吗?
答案 0 :(得分:0)
内部while循环没有退出。它在条件CPython
上循环,但循环内部没有任何内容修改Q.