TECH PIXEL

"Tech Pixel": Clearly mentions the site name. "Your go-to source for the latest tech news, reviews, and tutorials": Summarizes what the site offers. "Stay updated with the newest trends in technology": Highlights the value of staying current with tech trends. "Enhance your skills with our expert guides": Emphasizes the practical benefits and expertise available on the site.

Hand written Assignment using python

Hand written Assignment using python:

code:

 from tkinter import *

from tkinter import ttk
from googletrans import Translator, LANGUAGES

def Change(text="type", src="English", dest="Urdu"):
text1 = text
src1 = src
dest1 = dest

trans = Translator()
trans1= trans.translate(text, src=src1,dest=dest1)
return trans1.text

def data():
s = comb_sor.get()
d = comb_dest.get()
masg = sor_txt.get(1.0,END)
textget = Change(text=masg, src=s, dest=d)
dest_txt.delete(1.0,END)
dest_txt.insert(END, textget)

root = Tk()
root.title("Translator")
root.geometry("500x800")
root.config(bg="pink")

# Main title
lab_txt = Label(root, text="Translator", font=("time new roman", "30", "bold"), bg="yellow")
lab_txt.place(x= 100, y= 40, height= 50, width= 300)

# Frame for holding widgets
frame = Frame(root, bg="pink")
frame.pack(side=BOTTOM)

# Source text label
lab_source = Label(root, text="Source Text", font=("time new roman", "20", "bold"), bg="green")
lab_source.place(x=10, y=100, height=20, width=200)

# Source text box
sor_txt = Text(root, font=("time new roman", "10", "italic"), wrap=WORD)
sor_txt.place(x=25, y=140, height=150, width=450)

# Source language combo box
list_text = list(LANGUAGES.values())
comb_sor = ttk.Combobox(root, values=list_text)
comb_sor.place(x=10, y=300, height=30, width=150)
comb_sor.set("English")

# Translate button
button_change = Button(root, text="Translate", relief=RAISED, command=data)
button_change.place(x=170, y=300, height=30, width=150)

# Destination language combo box
comb_dest = ttk.Combobox(root, values=list_text)
comb_dest.place(x=340, y=300, height=30, width=150)
comb_dest.set("English")

lab_txt = Label(root, text="dest text", font=("time new roman", "30", "bold"), bg="pink")
lab_txt.place(x= 100, y= 350, height= 40, width= 300)

dest_txt = Text(root, font=("time new roman", "10", "italic"), wrap=WORD)
dest_txt.place(x=25, y=400, height=150, width=450)


root.mainloop()



The code uses the `pywhatkit` library to convert a block of text into a handwritten-style image and save it as "demo1.png". Here's a breakdown of the process:


1. **Importing the Library**:

   - `import pywhatkit as pw`: Imports the `pywhatkit` library with the alias `pw`.


2. **Defining the Text**:

   - `txt = """ ... """`: A multiline string containing the text to be converted into handwriting.


3. **Setting the Text Color**:

   - `[0, 0, 0]`: This is the RGB color code for black. It specifies that the text should be written in black.


4. **Converting Text to Handwriting**:

   - `pw.text_to_handwriting(txt, "demo1.png", [0, 0, 0])`: This function takes the text, converts it into a handwritten style, and saves it as an image file named "demo1.png".


5. **Print Statement**:

   - `print("END")`: This prints "END" to the console, indicating that the script has finished executing.


### Expected Output:

1. **Console Output**:

   - The console will display:

     ```

     END

     ```


2. **Generated Image**:

   - An image file named "demo1.png" will be created in the current working directory.

   - The image will contain the provided text rendered in a handwritten font, with the text color being black.


### How It Works:

1. **Text to Handwriting Conversion**:

   - The `pywhatkit.text_to_handwriting` function takes the provided text and converts each character into a handwritten style using a predefined font.


2. **Image Creation**:

   - The function generates an image where the text is drawn in the specified RGB color. The default background is white.

   

3. **Saving the Image**:

   - The generated image is saved as "demo1.png" in the current working directory.


Make sure you have the `pywhatkit` library installed. If not, you can install it using:

```bash

pip install pywhatkit

```


Once you run this code, you should find the "demo1.png" file in your working directory containing the handwritten-style text.

Post a Comment

0 Comments