Spongebob Text Generator

 


import ttkbootstrap as ttk
import tkinter as tk
import random
from ttkbootstrap.constants import *
from tkinter.filedialog import askdirectory

def spongelama():
    global yazi
    txt = yazi.get(0.0,tk.END).lower()
    yazi.delete(0.0,tk.END)
    indis = 0
    sponge_sayisi = int(len(txt) / 2)
    while sponge_sayisi > indis:
        r_sayi = random.randint(0,len(txt) - 1)
        if txt[r_sayi].islower() and txt[r_sayi].isspace() == False:
            txt = txt[0:r_sayi] + txt[r_sayi].upper() + txt[r_sayi + 1:]
            indis += 1
        else:
            pass
    yazi.insert(0.0,txt)
    indis = 0

def kaydet():
    dizin = askdirectory()
    dosya = open("{}/sponge.txt".format(dizin),"w")
    dosya.write(yazi.get(0.0,tk.END))
    dosya.close()

pencere = tk.Tk()
pencere.resizable(0,0)
stil = ttk.Style("darkly")
pencere.title("Spongebob Creator")
yazi = ttk.Text()
yazi.pack(padx=35,pady=38)
kaydet_btn = ttk.Button(text="Kaydet",bootstyle=INFO,command=kaydet)
kaydet_btn.place(x=200,y=512)
olustur_btn = ttk.Button(text="Oluştur",bootstyle=SUCCESS,command=spongelama)
olustur_btn.place(x=400,y=512)
pencere.mainloop()