2016-04-23 18 views
-2

GUI番号ゲームで問題が発生しました: ユーザーが正の数(零を超える桁数)を入力するようにします。フロートではありません。コンマはありません。私はそれらを削除することができます(ただし、私にはわかりません)。 If_ElseとException Handlingの概念は、私にとってはまだ新しいものです。Python 3 - 必要に応じてポップアップボックスが表示されない

問題私は直面しています:誤った情報が入力されたときにポップアップボックスを表示します。

from tkinter import * 
from tkinter import ttk 

class App(Tk): 
    def __init__(self): 
     Tk.__init__(self) 

     self.Number() 
     self.Output() 

    def Number(self): 
     Label (self, text = "Enter a positive whole number!").grid(row=1, column = 0) 
     self.Number = Entry(self) 
     self.Number.grid(row = 1, column = 1) 

    def Output(self): 
     self.btn = Button(self, text = "Check the number") 
     self.btn.grid(row = 8, column = 1) 
     self.btn["command"] = self.calculate 

    def calculate(self): 
     #Type cast the tkinter Entry to be an int 
     self.Number = int(self.Number.get()) 
     #Print the class type of the variable self.Number: 
     print (type(self.Number)) 

     #If the interger is equal to zero, display a custom popup box 
     if self.Number == 0: 
      self.newWindow = Toplevel(self) 
      Label(self.newWindow, text = "Please enter a number greater than zero!").grid() 
      self.newWindow.grid() 
     #Else if the number is less than zero, display a custom pop up box 
     elif self.Number <= 0: 
      self.newWindow = Toplevel(self) 
      Label(self.newWindow, text="Plase enter a positive whole number!") 
      self.newWindow.grid() 
     #Check to see if anything has been input at all 
     #Else if the length of the user's input is 0/null, display a custom pop up 
     elif len(self.Number) == 0: 
      self.newWindow = Toplevel(self) 
      Label(self.newWindow, text = "Please enter a number greater than zero!").grid() 
      self.newWindow.grid() 
     #Else if the number is not equal to an int, display a custom pop up 
     elif self.Number != int: 
      self.newWindow = Toplevel(self) 
      Label(self.newWindow, text = "Please enter a number greater than zero!").grid() 
      self.newWindow.grid() 
+0

あなたは* "いくつかの問題を抱えて" *何を意味するのですか? [mcve]を与える。 – jonrsharpe

+0

私は何をしてもポップアップボックスは表示されず、IDLEウィンドウにエラーが表示され続けます。 – cparks10

+1

*何か*エラーがありますか? – jonrsharpe

答えて

-1

あなたはPythonの組み込みisdigitを(使用することができます注)

test_strs=["12345", " 0123", "123.45", "-123", "123x5", "12*67", " 12 45", "0"] 
for eachstr in test_strs: 
    is_not=" IS NOT" 
    if eachstr.isdigit() : 
     is_not=" IS" 
    else: 
     ## display popup in a Toplevel 
    print "%7s %s a digit" % (eachstr, is_not) 
+0

私はあなたが質問に答えることさえしようとしないので、私はこれを "答えではない"と旗揚げしました。 –

関連する問題