Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8187461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:34:11+00:00 2026-06-07T02:34:11+00:00

I have the following Entry box where due to obtaining values I have put

  • 0

I have the following Entry box where due to obtaining values I have put a list option in for textvariable.

However I was wondering if it would be possible to put a default text in the background so to show which values are required in each box (like a greyscale text, ‘Value 1, value 2 etc..).

self.numbers = [StringVar() for i in xrange(self.number_boxes) ] #Name available in global scope.       
box=Entry(self.frame_table,bg='white',borderwidth=0, width=10, justify="center", textvariable=self.numbers[i])

Can I add in maybe something change ‘textvariable’ upon a mouse click inside the box or can I simply just add in another textvariable or text to set a default text?

  self.box = []

  for i in xrange(self.number_boxes):

        self.clicked = False
        self.box.append(Entry(self.frame_table,bg='white',borderwidth=0, width=10, justify="center", textvariable=self.numbers[i], fg='grey'))
        self.box[i].grid(row=row_list,column=column+i, sticky='nsew', padx=1, pady=1) 
        self.box[i].insert(0, "Value %g" % float(i+1))
        self.box[i].bind("<Button-1>", self.callback)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:34:12+00:00Added an answer on June 7, 2026 at 2:34 am

    In order to put default text in your Entry widget, you can use the insert() method as described here.

    box.insert(0, "Value 1")    # Set default text at cursor position 0.
    

    Now in order to change the contents of box after the user performs a mouse click inside the box, you will need to bind an event to the Entry object. For example, the following code deletes the contents of the box when it is clicked. (You can read about event and bindings here.) Below I show a full example of this.

    Note that deleting the text in the box is probably only practical for the first click (i.e. when deleting the default contents), so I created a global flag clicked to keep track of whether it has been clicked.

    from tkinter import Tk, Entry, END    # Python3. For Python2.x, import Tkinter.
    
    # Use this as a flag to indicate if the box was clicked.
    global clicked   
    clicked = False
    
    # Delete the contents of the Entry widget. Use the flag
    # so that this only happens the first time.
    def callback(event):
        global clicked
        if (clicked == False):
            box[0].delete(0, END)         #  
            box[0].config(fg = "black")   # Change the colour of the text here.
            clicked = True
    
    root = Tk()
    box = []                              # Declare a list for the Entry widgets.
    
    box.append(Entry(fg = "gray"))        # Create an Entry box with gray text.
    box[0].bind("<Button-1>", callback)   # Bind a mouse-click to the callback function.
    box[0].insert(0, "Value 1")           # Set default text at cursor position 0.
    
    box.append(Entry(fg = "gray"))        # Make a 2nd Entry; store a reference to it in box.
    box[1].insert(0, "Value 2")
    
    box[0].pack()                         #
    box[1].pack()
    
    if __name__ == "__main__":
        root.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following entry in my database: t.time :my_time_stamp In my controller I
I'm using Spring and struts and have the following entry in '/META-INF/context.xml' <Context cachingAllowed=false
I have the following log entry that I am processing in PowerShell I'm trying
I have been following the validation for Entry boxes from here . The code
I have the following code in my index view. latest_entry_list = Entry.objects.filter(is_published=True).order_by('-date_published')[:10] for entry
I have the following in an XML file: <entry> ... <link href=http://www.example.com/somelink /> ...
I have the following XML Document: <?xml version=\1.0\ encoding=\UTF-8\?> <atom:entry xmlns:atom=\http://www.w3.org/2005/Atom\ xmlns:apps=\http://schemas.google.com/apps/2006\ xmlns:gd=\http://schemas.google.com/g/2005\> <apps:property
I have the following code. // mfc.cpp : Defines the entry point for the
I'm trying to create a Tkinter GUI that saves all entry box values into
I have the following entry in a properties file: some.key = \n [1:Some value]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.