Question

Is there a way to have a text box in the GUI that will have a default text display?

I want the text box will have "Please set the path of the file you want..." However, when I run it - it is blank...

My code is as follows:

  path=StringVar()
  textEntry=Entry(master,textvariable=path,text='Please set the path of the file you want...')
  textEntry.pack()
Was it helpful?

Solution

This should demonstrate how to do what you want:

import Tkinter as tk

root = tk.Tk()

entry = tk.Entry(root, width=40)
entry.pack()
# Put text in the entrybox with the insert method.
# The 0 means "at the begining".
entry.insert(0, 'Please set the path of the file you want...')

text = tk.Text(root, width=45, height=5)
text.pack()
# Textboxes also have an insert.
# However, since they have a height and a width, you need to
# put 0.0 to spcify the beginning.  That is basically the same as
# x=0, y=0.
text.insert(0.0, 'Please set the path of the file you want...')

root.mainloop()

OTHER TIPS

path.set("Please set the path of the file you want...")

-or-

textEntry.insert(0, "Please set the path of the file you want...")

Useful documentation:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top