Good example of functional testing a Python Tkinter application

Let us suppose that we have a GUI-based Python tkinter application that takes the text input from the user and validates by saving it in a new text file. The file contains the same text input that the user has typed. We can check and validate the user input from the file.

In Functional Testing, we are primarily concerned about backend API, database, user-server communication, Input and output, etc.

To check the application using the functional testing strategy, we have to first understand the user requirement and the input/output. After testing the pre-phase, we test our application for different test cases.

For example, we have a GUI-based tkinter application that takes the user input and saves it in the form of a text file in the system.


from tkinter import *

win = Tk()


# Create title label
title_label = Label(win, text="Enter the File Name")

# Create title entry
title_entry = Entry(win, width=35)

# Create save button and function
def save():
   # Get contents of title entry and text entry
   # Create a file to write these contents in to it
   file_title = title_entry.get()
   file_contents = text_entry.get(0.0, END)
   with open(file_title + ".txt", "w") as file:
      print("File successfully created")
#Create a save button to save the content of the file
save_button = Button(win, text="Save The File", command=save)

# Create text entry
text_entry = Text(win, width=40, height=30, border=4, relief=RAISED)



Running the above code will create a window like this,

Once we will click the Save the File button, it will save the filename as “Tutorials.txt”.

Now, go to the file location and open the text file externally. It will have the same text as the user input.