-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
86 lines (57 loc) · 2.42 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# for graphical user interface
from math import fabs
from tkinter import Tk, Label, Button, Entry
# classes
from farmer_redirect import Register
from check_conditions import create_message
# running the function continuously
create_message()
# checking the farmer's records
def check_user(user, pwd):
'''function to check if the user is registered. If not, it takes the farmer to registration'''
# creating an instance of the Register class
farmer_register = Register(window, user, pwd, welcome_label, create_message())
registered_farmer = open("farmer_record.csv", "r")
for record in registered_farmer:
if user == record.split(",")[0].strip() and pwd == record.split(",")[1].strip():
farmer_register.success_registration()
return None
registered_farmer.close()
# registering the farmer
farmer_register.capture_data()
# GUI welcome function after log in button
def welcome():
'''Function that welcomes the user'''
user = username.get() # Taking the input from the entry widget
pwd = password.get()
# checking if the entry box is not empty
if user != "":
username_label.destroy()
welcome_label.config(text="Hello, Farmer " + user)
username.destroy()
welcome_label.grid(row=0, column=0, columnspan=3)
login_button.destroy()
password_label.destroy()
password.destroy()
check_user(user, pwd)
# ------------- Graphical User Interface ------------------
# initialising the graphical user interface window
window = Tk()
# screen title
window.title("Spraying Management App")
window.config(padx=100, pady=100, background="lightgreen")
# font
font_name = "Courier"
welcome_label = Label(window, text="Welcome to Spraying Management App", font=(font_name, 20, "bold"), fg="red", bg="white")
welcome_label.grid(row=0, column=0, columnspan=3, pady=20)
username_label = Label(window, text="Enter Username: ", fg="red")
username_label.grid(row=1, column=0)
username = Entry(window, width = 50)
username.grid(row=1, column=1)
password_label = Label(window, text="Enter Password: ", fg="red")
password_label.grid(row=2, column=0)
password = Entry(window, width = 50)
password.grid(row=2, column=1)
login_button = Button(window, text="Log in", command = welcome, font=(font_name, 10, "bold"), fg="red", bg="white")
login_button.grid(row=3, column=1, padx=10, pady=10)
window.mainloop()