Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Python

Python Tkinter Application का Functional Testing का अच्छा उदाहरण

मान लीजिए हमारे पास एक GUI-based Python tkinter application है जो user से text input लेता है और इसे new text file में save करके validate करता है। File में वही text input होता है जो user ने type किया है। हम file से user input check और validate कर सकते हैं।

Functional Testing में, हम primarily backend API, database, user-server communication, Input और output आदि के बारे में concerned होते हैं।

Functional testing strategy का उपयोग करके application check करने के लिए, हमें पहले user requirement और input/output समझना होगा। Pre-phase test करने के बाद, हम अपने application को different test cases के लिए test करते हैं।

उदाहरण के लिए, हमारे पास एक GUI-based tkinter application है जो user input लेता है और इसे system में text file के रूप में save करता है।

उदाहरण

from tkinter import *

win = Tk()
win.geometry("700x600")

# Create title label
title_label = Label(win, text="Enter the File Name")
title_label.pack(anchor='n')

# Create title entry
title_entry = Entry(win, width=35)
title_entry.pack(anchor='nw')

# 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:
        file.write(file_contents)
        print("File successfully created")
        file.close()
    pass

# Create a save button to save the content of the file
save_button = Button(win, text="Save The File", command=save)
save_button.pack()

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

win.mainloop()

आउटपुट

उपरोक्त code चलाने से इस तरह की window बनेगी,

Python Tkinter Application का Functional Testing का अच्छा उदाहरण

एक बार जब हम Save the File button पर क्लिक करेंगे, तो यह filename को "Tutorials.txt" के रूप में save करेगा।

अब, file location पर जाएं और text file को externally open करें। इसमें वही text होगा जो user input था।

Python Tkinter Application का Functional Testing का अच्छा उदाहरण

  1. पायथन ट्किंटर में asksaveasfile() फ़ंक्शन पायथन ट्किंटर में asksaveasfile() फ़ंक्शन

    TKinter पायथन में GUI प्रोग्रामिंग के लिए एक मॉड्यूल है। हम एक कैनवास बनाते हैं और उस पर कई गुणों और व्यवहारों के साथ अपने UI घटक रखते हैं। इस लेख में, हम देखेंगे कि asksaveasfile फ़ंक्शन का उपयोग करके पायथन प्रोग्राम के माध्यम से बनाई गई फ़ाइलों को स्थानीय ड्राइव में कैसे सहेजा जाए।हम पहले एक कैनवा

  1. Python Tkinter में askopenfile() फ़ंक्शन Python Tkinter में askopenfile() फ़ंक्शन

    किसी फाइल के पथ को हार्डकोड करने के बजाय जिसे Python प्रोग्राम द्वारा उपयोग किया जाना है, हम उपयोगकर्ता को GUI का उपयोग करके OS फ़ोल्डर संरचना को ब्राउज़ करने और फाइल का चयन करने की अनुमति दे सकते हैं। यह tkinter मॉड्यूल का उपयोग करके प्राप्त किया जाता है जिसमें हम एक कैनवास परिभाषित करते हैं और उस

  1. पायथन में बर्थडे रिमाइंडर एप्लिकेशन पायथन में बर्थडे रिमाइंडर एप्लिकेशन

    इस खंड में हम देखेंगे कि पायथन का उपयोग करके बर्थडे रिमाइंडर एप्लिकेशन कैसे बनाया जाए। समस्या कथन पायथन का उपयोग करके एक एप्लिकेशन बनाएं, जो जांच सके कि वर्तमान दिन पर कोई बर्थडे है या नहीं। यदि सूचीबद्ध किसी व्यक्ति का बर्थडे आज है, तो उस व्यक्ति के नाम के साथ सिस्टम पर एक नोटिफिकेशन भेजें। हमें