1
+
2
+ #--------------------------------------------------|
3
+ #--- Application that calculates the number ---|
4
+ #--- that is located in the selected position. ---|
5
+ #--------------------------------------------------|
6
+
7
+ #----- Import of the Tkinter library -----#
8
+ import tkinter as tk
9
+ from tkinter import *
10
+
11
+ #----- Tkinter Settings -----#
12
+ root = tk .Tk ()
13
+ root .geometry ("800x360" )
14
+ root .configure (background = "#3DC1AC" )
15
+ root .resizable (False , False )
16
+ tk .Wm .wm_title (root , "Fibonacci Sequence" )
17
+ entr = tk .StringVar (root )
18
+ output = tk .StringVar (root )
19
+ inpt = tk .StringVar (root )
20
+
21
+
22
+ #----- Function that calculates the number found in the selected position -----#
23
+ def calc ():
24
+ result = [1 ]
25
+ num = int (inpt .get ()) - 1
26
+ if num > - 1 and num < 112 :
27
+ for i in range (num ):
28
+ if len (result ) < 2 :
29
+ result .append (result [i - 1 ])
30
+ else :
31
+ result .append (result [len (result )- 1 ]+ result [len (result )- 2 ])
32
+ output .set (result [- 1 ])
33
+ else :
34
+ output .set ("Only from 1 to 112" )
35
+
36
+ #----- Function that removes the content of the output and input -----#
37
+ def delet ():
38
+ output .set ("" )
39
+ inpt .set ("" )
40
+
41
+
42
+ #----- Send Button -----#
43
+ tk .Button (
44
+ root ,
45
+ text = "SEND" ,
46
+ font = ("Courier" , 20 , "bold" ),
47
+ bg = "#50C878" ,
48
+ command = calc ,
49
+ ).place (x = 410 ,y = 100 )
50
+
51
+ #----- Delete Button -----#
52
+ tk .Button (
53
+ root ,
54
+ text = "DELETE" ,
55
+ font = ("Courier" , 20 , "bold" ),
56
+ bg = "#E41B17" ,
57
+ command = delet ,
58
+ ).place (x = 600 ,y = 100 )
59
+
60
+ #----- TEXT LABELS -----#
61
+ tk .Label (
62
+ root ,
63
+ text = "POSITION:" ,
64
+ font = ("Courier" , 40 , "bold" ),
65
+ bg = "#3DC1AC" ,
66
+ ).place (x = 40 ,y = 30 )
67
+
68
+ tk .Label (
69
+ root ,
70
+ text = "RESULT:" ,
71
+ font = ("Courier" , 40 , "bold" ),
72
+ bg = "#3DC1AC" ,
73
+ ).place (x = 40 ,y = 150 )
74
+
75
+
76
+ #----- Information entry -----#
77
+ entr = tk .Entry (
78
+ bg = "#008B8B" ,
79
+ font = ("Courier" , 30 , "bold" ),
80
+ width = 16 ,
81
+ border = 2 ,
82
+ relief = "solid" ,
83
+ justify = "center" ,
84
+ textvariable = inpt ,
85
+ ).place (x = 370 ,y = 30 ,height = 60 )
86
+
87
+ #----- Information output -----#
88
+ out = tk .Label (
89
+ bg = "#99ff66" ,
90
+ fg = "Black" ,
91
+ font = ("Courier" , 36 , "bold" ),
92
+ textvariable = output ,
93
+ bd = 2 ,
94
+ relief = "solid" ,
95
+ width = 24 ,
96
+ ).place (x = 40 , y = 230 , height = 70 )
97
+
98
+
99
+ root .mainloop ()
0 commit comments