0

I have a searchbox that is an Entry in tkinter and I want to have an X-button in the right corner that the user can click on and it will delete everything that was typed in the box. But I cannot fin a solution on how to put a Label or Button inside Entry. Any suggestions?

Thanks in advance

Sandyy95
  • 1
  • 2

1 Answers1

0

this is an oop solution, init function creates widgets and the clear function deletes the text inside the entry. You can arrange the position of the widgets with pack(), grid() would also work.

here is a similar question: How to clear the Entry widget after a button is pressed in Tkinter?

import tkinter as tk
from tkinter import ttk

class App(tk.Frame):
    def __init__(self, master):
        tk.Frame.__init__(self, master)
        self.entryText = ttk.Entry(self)
        self.entryText.pack()
        self.XButton = ttk.Button(self, text="X-Button", command=self.clear_text).pack()

    def clear_text(self):
        self.entryText.delete(0, 'end')

if __name__ == "__main__":
    root = tk.Tk()
    root.geometry('200x100')
    App(root).pack()
    root.mainloop()
thomkell
  • 195
  • 1
  • 11