Created
December 8, 2017 08:26
-
-
Save shimano-zd/7d9cb47c983223109d27a833ac398fab to your computer and use it in GitHub Desktop.
python window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter as tk | |
class Example(tk.Frame): | |
def __init__(self, parent): | |
tk.Frame.__init__(self, parent) | |
# create a prompt, an input box, an output label, | |
# and a button to do the computation | |
self.prompt = tk.Label(self, text="Unesite neki broj: \n Klikom na 'Provjeri' program će \n provjeriti je li prost", anchor="w") | |
self.entry = tk.Entry(self) | |
self.submit = tk.Button(self, text="Provjeri", command = self.calculate) | |
self.output = tk.Label(self, text="Rezultat: ") | |
# lay the widgets out on the screen. | |
self.prompt.pack(side="top", fill="x", padx=100) | |
self.entry.pack(side="top", fill="x", padx=100, pady=20) | |
self.output.pack(side="top", fill="x", expand=True) | |
self.submit.pack(side="right", fill="x", padx = 10, pady = 10) | |
def calculate(self): | |
# get the value from the input widget, convert | |
# it to an int, and do a calculation | |
try: | |
i = int(self.entry.get()) | |
d = 0 | |
for j in range(1,i+1): | |
if i%j == 0: | |
d = d+1 | |
if d > 2 : | |
result = "Uneseni broj je složen!" | |
else: | |
result = "Uneseni broj je prost!" | |
except ValueError: | |
result = "Uneseni broj nije u skupu cijelih brojeva!" | |
# set the output widget to have our result | |
self.output.configure(text=result) | |
# if this is run as a program (versus being imported), | |
# create a root window and an instance of our example, | |
# then start the event loop | |
if __name__ == "__main__": | |
root = tk.Tk() | |
Example(root).pack(fill="both", expand=True) | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment