Is there any way to remove duplicate lines in tkinter?
Here's the code:
from tkinter import *
root = Tk()
def remove_duplicate():
# Code to remove all duplicate lines in the text widget
pass
text = Text(root , width = 65, height = 20, font = "consolas 14")
text.pack()
text.insert('1.0' , '''Hello world\n\nHello world\n\nBye bye\n\n\n\n\nBye bye\nBye bye''')
remove_button = Button(root , text = "Remove Duplicate Lines" , command = remove_duplicate)
remove_button.pack()
mainloop()
Here when I click on the remove_button
, I want all the duplicate lines in my text widget to be removed.
In this case, I have the string:
"""
Hello world
Hello world
Bye bye
Bye bye
Bye bye
"""
, so when I remove the duplicate lines, I should get something like:
"""
Hello world
Bye bye
"""
Is there any way to achieve this in tkinter?
It would be great if anyone could help me out.