How to add a placeholder in Tkinter

前端 未结 1 404
闹比i
闹比i 2021-01-25 05:38

How would I add a placeholder to an entry in tkinter? I don\'t believe it has a placeholder function like HTML for example. I figured out that to make the text disa

相关标签:
1条回答
  • 2021-01-25 05:58

    U can't add placeholder like HTML as far as i know, but u can make similar behavior. When you make entry you can do something like>

    from tkinter import *   
    
    def clear_entry(event, entry):
        entry.delete(0, END)
    
    root = Tk()
    
    entry = Entry(root)
    
    entry.pack()
    placeholder_text = 'some text'
    entry.insert(0, placeholder_text)
    
    entry.bind("<Button-1>", lambda event: clear_entry(event, entry))
    
    root.mainloop()
    

    P.S: I've wrote this from my head , haven't tested it

    0 讨论(0)
提交回复
热议问题