I'm trying to create a small GUI that when the user enters a number into a text box, and it displays (as a label) whether it is a prime number or not.
The code I have currently "works" (as in no errors are displayed) but the label doesn't change.
The prime number code works in the python shell.
My code is as follows:
from tkinter import *
root = Tk()
label1 = Label( root, text="Enter Number")
E1 = Entry(root, bd =5)
def isPrime():
entry1 = E1.get()
entry1 = int(entry1)
for d in range(2,entry1):
if entry1 % d == 0:
label1 = Label(root, text="Not prime")
root.update_idletasks()
break
else:
label1 = Label(root, text="Is prime")
submit = Button(root, text ="Submit", command = isPrime)
root.update_idletasks()
label1.pack()
E1.pack()
submit.pack(side =BOTTOM)
root.mainloop()
Thanks for any help in advance, and please let me know if you'd like any more clarification about any issues. Thanks.
label1["text"] = "Is prime"for example.