Home > Net >  How to skip the rest of function after a specific condition in the function itself
How to skip the rest of function after a specific condition in the function itself

Time:11-24

I want to Skip the Entire Function after if save_perm == 0 : Then i want to skip the rest of the code

I am a Beginner and making a Basic Notepad which has basic functions Any Simple keyword or command Suggestions will be apprciated

from tkinter import *
from tkinter.messagebox import askyesno


def save_func():
    global file_path
    txt = text.get("1.0", END)
    if "file_path" in globals():
        save_perm = askyesno("Save the File", "Do You Want to Save the File")
        if save_perm:
            breakpoint
    else:
        text_savefile_window = asksaveasfile(
            initialfile="Untitled.txt",
            title="Select Name and Path",
            defaultextension=".txt",
            filetypes=[("All Files", "*.*"), ("Text Documents", "*.txt")],
        )
        file_path = text_savefile_window.name()

    text_file = open(file_path, "w ")
    text_file.write(txt)
    text_file.close()


save_func()

CodePudding user response:

Use return to exit the function

CodePudding user response:

Just after the condition, write

return
  • Related