【问题标题】:MessageBox not disapearing after I click ok单击确定后消息框不会消失
【发布时间】:2018-10-09 22:25:23
【问题描述】:

我正在尝试使用 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()

我不确定为什么单击确定后消息框没有消失。无论如何,Tkinter 是否可以做到这一点?

【问题讨论】:

    标签: python python-2.7 tkinter tkmessagebox


    【解决方案1】:

    内部的while循环没有出口。它在条件 Q == True 上循环,但循环内没有任何内容修改 Q。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多