How to insert text string into ttk Entry?
Question:
I want to add/delete a string to ttk
Entry
. How?
I’m new in tkinter
Entry
but I don’t know how in ttk
Entry
.
This is code to insert any string in tkinter
Entry
:
from tkinter import *
root = Tk()
my_entry = Entry(root,font=("arial",10,"bold")).pack()
my_entry.insert(0, "GG") # Working :)
root.mainloop()
so I don’t know How in the ttk
Entry Help:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
my_entry = ttk.Entry(root,font=("arial",10,"bold")).pack()
my_entry.insert(0, "GG") #Not Working :(
root.tk.mainloop()
Answers:
Change the line like this:
my_entry = ttk.Entry(root,font=("arial",10,"bold"))
my_entry.pack()
It is the wrong way to say Entry(..).pack()
in python as in python x = a().b()
, x
will get the value returned by b()
in this case pack()
and pack()
returns None
so then my_entry
becomes None
, so your trying to call insert()
in None
, which will give you the error your facing
AttributeError: NoneType object has no attribute insert()
Final Code:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
my_entry = ttk.Entry(root,font=("arial",10,"bold"))
my_entry.pack()
my_entry.insert(0, "GG") #Not Working :(
root.tk.mainloop()
Also keep a note, that your first and second examples in Q will give the exact same error.
I want to add/delete a string to ttk
Entry
. How?
I’m new in tkinter
Entry
but I don’t know how in ttk
Entry
.
This is code to insert any string in tkinter
Entry
:
from tkinter import *
root = Tk()
my_entry = Entry(root,font=("arial",10,"bold")).pack()
my_entry.insert(0, "GG") # Working :)
root.mainloop()
so I don’t know How in the ttk
Entry Help:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
my_entry = ttk.Entry(root,font=("arial",10,"bold")).pack()
my_entry.insert(0, "GG") #Not Working :(
root.tk.mainloop()
Change the line like this:
my_entry = ttk.Entry(root,font=("arial",10,"bold"))
my_entry.pack()
It is the wrong way to say Entry(..).pack()
in python as in python x = a().b()
, x
will get the value returned by b()
in this case pack()
and pack()
returns None
so then my_entry
becomes None
, so your trying to call insert()
in None
, which will give you the error your facing
AttributeError: NoneType object has no attribute insert()
Final Code:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
my_entry = ttk.Entry(root,font=("arial",10,"bold"))
my_entry.pack()
my_entry.insert(0, "GG") #Not Working :(
root.tk.mainloop()
Also keep a note, that your first and second examples in Q will give the exact same error.