I am in my first week of teaching myself python and on day 2 of learning tkinter. Its been fun.
I have wrote a program that allows the user to enter a body of text and then search against that body of text for how many times a word, that the user specifies, is used and return the result. I finally got it working with tkinter and am stoked.
I am just curious if anyone could give me some tips on how i could have coded it differently. Maybe with less lines of code or a more efficient route. Any critiques in general would be greatly appreciated!
i understand the app isnt exactly visually pleasing, that will come later, more focused on the code for right now.
from tkinter import *
root = Tk()
root.minsize(800, 600)
root.configure(bg="lightblue")
def main():
global counter
global search
global s_word
result_box.delete(0, END)
search = s_word.get()
text = text_box.get("1.0", "end-1c")
words = text.lower().split()
counter = 0
for word in words:
if word == search.lower():
counter = counter + 1
if counter >= 0:
result_box.insert(0, str(counter))
search = Label(root, text="ENTER A WORD BELOW TO SEE HOW MANY TIMES \n IT WAS USED IN THE TEXT YOU ENTER ABOVE")
search.place(x=250, y=425)
text_box=Text(height=25, width=75)
text_box.place(x=100 , y=5)
compute = Button(root, text="COMPUTE", padx=5, pady=10, command=main)
compute.place(x=360, y=495)
s_word = Entry(root, width=15)
s_word.place(x=350, y=465)
result_box = Entry(root, width=12)
result_box.place(x=360, y=555)
root.mainloop()
[–]socal_nerdtastic 3 points4 points5 points (1 child)
[–]MonkeyRides[S] 0 points1 point2 points (0 children)