Skip to content Skip to sidebar Skip to footer

Change Default Tkinter Entry Value In Python

checkLabel = ttk.Label(win,text = ' Check Amount ', foreground = 'blue') checkLabel.grid(row = 0 , column = 1) checkEntry = ttk.Entry(win, textvariable = checkVariable) checkEntr

Solution 1:

Use the entry widget's function, .insert() and .delete(). Here is an example.

entry = tk.Entry(root)
entry.insert(END, "Hello") # this will start the entry with "Hello" in it# you may want to add a delay or something here. 
entry.delete(0, END) # this will delete everything inside the entry
entry.insert(END, "WORLD") # and this will insert the word "WORLD" in the entry.

Another way to do this is with the Tkinter StrVar. Here is an example of using the str variable.

entry_var = tk.StrVar()
entry_var.set("Hello")
entry = tk.Entry(root, textvariable=entry_var) # when packing the widget# it should have the world "Hello" inside.# here is your delay or you can make a function call.
entry_var.set("World") # this sets the entry widget text to "World"

Solution 2:

Set the value of checkVariable to '' (the empty string) before you create the Entry object? The statement to use would be

checkVariable.set('')

But then checkVariable would have to be a StringVar, and you would have to convert the input value to an integer yourself if you wanted the integer value.

Post a Comment for "Change Default Tkinter Entry Value In Python"