
my_str=t1.get("1.0",'end-1c') # read the inputs
my_str = my_str.replace('\n', ' ').replace('\r', '')# linebreak carriage
create a list from this string by using split(), one space is used as delimiter.
tags_all=my_str.split(' ') # break with one space gap to create list
tags_remove=['all','All','to','To','And','and','or','is','.',',']
tags_all=list(set(tags_all)-set(tags_remove))
The above list of negative words ( tags_remove ) can be taken from database or from other sources. There are many sample lists are available in Internet.
tags_all=['#' + s for s in tags_all] # add hash to all elements
Using the list ( tags_all ) we will create a string. We have used map() to convert each element of the list to string before joining them using join().
my_str = ' '.join(map(str, tags_all)) # from list create string
Remove the previous data if any and then add the string to Text widget ( t2 ).
t2.delete('1.0','end') # remove the previous entry if any
t2.insert(tk.END, my_str) # add to text
In this tool the data is available within the application. To copy to clipboard and take out we have to use pyperclip library. Install pyperclip
pip install pyperclip
To copy
t2.tag_add("sel", "1.0","end") # all text selected
t2.tag_config("sel",background="green",foreground="red")
pyperclip.copy(t2.selection_get()) # copy to clipboard
import tkinter as tk
#from tkinter import END
import pyperclip # to copy data to system clipboard
my_w = tk.Tk()
my_w.geometry("700x500") # Size of the window
my_w.title("www.plus2net.com") # Adding a title
l1 = tk.Label(my_w, text='Your Data', width=10,font=20 ) # added one Label
l1.grid(row=0,column=0,padx=10,pady=10,columnspan=2)
t1 = tk.Text(my_w,height=6, width=50,bg='yellow',font=28) # text box
t1.grid(row=1,column=0,padx=10,columnspan=2)
b1=tk.Button(my_w,text='Generate hashtags #',font=22,command=lambda:my_tags())
b1.grid(row=2,column=0,pady=5)
t2=tk.Text(my_w,height=6,width=50,font=14)
t2.grid(row=3,column=0,padx=20,pady=20)
def my_tags():
my_str=t1.get("1.0",'end-1c') # read the inputs
my_str = my_str.replace('\n', ' ').replace('\r', '')# linebreak carriage
tags_all=my_str.split(' ') # break with one space gap to create list
tags_remove=['all','All','to','To','And','and','or','is','.',',']
tags_all=list(set(tags_all)-set(tags_remove))
tags_all=['#' + s for s in tags_all] # add hash to all elements
my_str = ' '.join(map(str, tags_all)) # from list create string
t2.delete('1.0','end') # remove the previous entry if any
#print(tags_all)
t2.insert(tk.END, my_str) # add to text
t2.tag_add("sel", "1.0","end") # all text selected
t2.tag_config("sel",background="green",foreground="red")
pyperclip.copy(t2.selection_get()) # copy to clipboard
my_w.mainloop() # Keep the window open
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.