forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
95 lines (58 loc) · 2.28 KB
/
script.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
84
85
86
87
88
89
90
91
92
93
94
95
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
from tkinter import *
def detect_sentiment():
sentence = textArea.get("1.0", "end")
sid_obj = SentimentIntensityAnalyzer()
sentiment_dict = sid_obj.polarity_scores(sentence)
string = str(sentiment_dict['neg']*100) + "% Negative"
negativeField.insert(10, string)
string = str(sentiment_dict['neu']*100) + "% Neutral"
neutralField.insert(10, string)
string = str(sentiment_dict['pos']*100) + "% Positive"
positiveField.insert(10, string)
if sentiment_dict['compound'] >= 0.05:
string = "Positive"
elif sentiment_dict['compound'] <= - 0.05:
string = "Negative"
else:
string = "Neutral"
overallField.insert(10, string)
def clearAll():
negativeField.delete(0, END)
neutralField.delete(0, END)
positiveField.delete(0, END)
overallField.delete(0, END)
textArea.delete(1.0, END)
gui = Tk()
gui.config(background="light blue")
gui.title("Sentiment Detector")
gui.geometry("500x500")
enterText = Label(gui, text="Enter Your Sentence", bg="light blue")
textArea = Text(gui, height=10, width=53, font="lucida 13")
check = Button(gui, text="Check Sentiment", fg="Black",
bg="light yellow", command=detect_sentiment)
negative = Label(gui, text="sentence was rated as: ", bg="light blue")
neutral = Label(gui, text="sentence was rated as: ", bg="light blue")
positive = Label(gui, text="sentence was rated as: ", bg="light blue")
overall = Label(gui, text="Sentence Overall Rated As: ", bg="light blue")
negativeField = Entry(gui)
neutralField = Entry(gui)
positiveField = Entry(gui)
overallField = Entry(gui)
clear = Button(gui, text="Clear", fg="Black",
bg="light yellow", command=clearAll)
Exit = Button(gui, text="Exit", fg="Black", bg="light yellow", command=exit)
enterText.grid(row=0, column=2)
textArea.grid(row=1, column=2, padx=10, sticky=W)
check.grid(row=2, column=2)
neutral.grid(row=3, column=2)
neutralField.grid(row=4, column=2)
positive.grid(row=5, column=2)
positiveField.grid(row=6, column=2)
negative.grid(row=7, column=2)
negativeField.grid(row=8, column=2)
overall.grid(row=9, column=2)
overallField.grid(row=10, column=2)
clear.grid(row=11, column=2)
Exit.grid(row=12, column=2)
gui.mainloop()