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)
In order to put default text in your
Entrywidget, you can use theinsert()method as described here.Now in order to change the contents of
boxafter the user performs a mouse click inside the box, you will need to bind an event to theEntryobject. 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
clickedto keep track of whether it has been clicked.