2. OBJECTIVE
In this python programming project, I applied to count the
total words and characters in a string. The program will take the string as input from
the user, count the words and characters and then it will print out the results on the
GUI.
4. What is Tkinter ?
The tkinter package (“Tk interface”) is the standard Python interface to the Tk GUI
toolkit. Both Tk and tkinter are available on most Unix platforms, as well as on
Windows systems. (Tk itself is not part of Python; it is maintained at ActiveState.)
Tkinter is lightweight and relatively painless to use compared to other frameworks.
This makes it a compelling choice for building GUI applications in Python,
especially for applications where a modern sheen is unnecessary, and the top
priority is to build something that’s functional and cross-platform quickly.
5. Step -1
To use Tkinter , firstly we have to import Tkinter modules.
6. Step 2
Opening the new empty window with ‘Tk()’
Giving a name to window with ‘title()’
Adjusting the background color with ‘configure()’
Adjusting the size of window with ‘geometry()’
Arranging the permissions to resizable with ‘resizable()’
window
7. Step 3
I created the TEXT label with adjusting of ; Label()
1. Name of label ---- text=‘ ‘
2. Background color----bg=‘ ‘
3. Word color----fg=‘ ’
4. Size of label----width=‘’
5. Position of label on the window--- grid()
9. Step-4
I created entry label with ‘Entry()’
Configured to arrange the entry type with ‘StringVar()’
Adjusting location of label on the window with ‘grid()’
window
10. Step -5
I created the ‘Character’ and ‘word’ labels with adjusting of ; Label()
1. Name of label ---- text=‘ ‘
2. Background color----bg=‘ ‘
3. Word color----fg=‘ ’
4. Size of label----width=‘’
5. Position of label on the window--- grid()
12. Step-6
I created entry labels with ‘Entry()’ for char and word
Configured to arrange the entry type with ‘DoubleVar()’ to be able integer values for char and
word results.
Adjusting location of label on the window with ‘grid()’
window
13. Step -7
Buttons ,which are clear and calculate, were created to call functions and buttons were configured
with ‘Button()’
Location of buttons were adjusted with ‘grid()’
Clear button calls ‘clear’ function.
Calculate button calls ‘calculatee’ function
15. Step-8
To calculate number of words of the input text, ‘calculate’ function was defined.
With get() function , string is getting from ‘ft_entry’.
And, with using str() function, we get string values.
In addition, values is seperated word by word from sentences by using ‘split()’
function,and we get word list, like figure.i and figure.o
Number of words is calculated by using len() function.
Finally , we send the number of words to word label with ‘set()’ func.
Figure.i Figure.o
İnput to output
for split()
16. Step -9
On the continue of ‘calculatee’ function; in the list ,which is created by split() before, the every
word is entried to len() function and number of characters are sent to mt_value2 by set() function.
On the other hand , ‘clear’ function was defined to clear input and outputs by using set(‘’).
20. Example -3
INPUT : In this python programming tutorial, we will learn how to count the
total words and characters in a string. The program will take the string as input from the user,
count the words and characters and then it will print out the result.
OUTPUT :