Probleme mit meiner GUI-Nummer Spiel: Ich möchte der Benutzer eine positive Zahl eingeben (größer als Null Interger). Kein Schwimmer. Keine Kommas, ich kann sie entfernen (obwohl ich nicht weiß, wie.) If_Else und Exception Handling-Konzepte sind für mich noch neu.Python 3 - Pop-up-Boxen erscheinen nicht wie erforderlich
Problem Ich stehe vor: Ich möchte Pop-up-Boxen erscheinen, wenn falsche Informationen eingegeben wurden.
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()
Was meinen Sie * "mit ein paar Probleme" *? Gib ein [mcve]. – jonrsharpe
Egal was ich mache, die Popup-Boxen erscheinen nicht, und ich bekomme immer wieder Fehler im IDLE-Fenster. – cparks10
* Was * Fehler ?! – jonrsharpe