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()