How to clear/delete the contents of a Tkinter Text widget?

后端 未结 7 1327
谎友^
谎友^ 2020-12-09 01:05

I am writing a Python program in TKinter on Ubuntu to import and print the name of files from particular folder in Text widget. It is just adding f

7条回答
  •  庸人自扰
    2020-12-09 01:42

    from Tkinter import *
    
    app = Tk()
    
    # Text Widget + Font Size
    txt = Text(app, font=('Verdana',8))
    txt.pack()
    
    # Delete Button
    btn = Button(app, text='Delete', command=lambda: txt.delete(1.0,END))
    btn.pack()
    
    app.mainloop()
    

    Here's an example of txt.delete(1.0,END) as mentioned.

    The use of lambda makes us able to delete the contents without defining an actual function.

提交回复
热议问题