Instead of having a variable point directly to a Integer you should use IntVar(). The reason for this is because when you set a textvariable to the Entry Box you need to either use IntVar() or StringVar(). This will allow the value to be updated any time you type something in the Entry Box or any time you update the value of the IntVar in your code.

Take a look at this modified example of your code. I cleaned it up a bit and made it conform a little better to PEP8 standards. I also changed your self.integer to an IntVar().

import tkinter as tk
class Main(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
#INTEGER
self.integer = tk.IntVar()
self.integer.set(0)
#BUTTONS
tk.Button(self, text='Quit', command=self.destroy).pack()
tk.Button(self, text='+', command=self.plus_one).pack()
tk.Button(self, text='-', command=self.take_one).pack()
#ENTRY
self.entry0 = tk.Entry(self, textvariable=str(self.integer), justify="center", width=4)
self.entry0.pack()
def plus_one(self):
x = self.integer.get() + 1
self.integer.set(x)
def take_one(self):
x = self.integer.get() - 1
self.integer.set(x)
app = Main()
app.mainloop()

To check if the IntVar() is being updated automatically no mater how you add to the Entry box you can use a button that prints the self.integer to make sure this is working properly.

import tkinter as tk
class Main(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
#INTEGER
self.integer = tk.IntVar()
self.integer.set(0)
#BUTTONS
tk.Button(self, text='Quit', command=self.destroy).pack()
tk.Button(self, text='+', command=self.plus_one).pack()
tk.Button(self, text='-', command=self.take_one).pack()
tk.Button(self, text="Print IntVar", command=self.print_intvar).pack()
#ENTRY
self.entry0 = tk.Entry(self, textvariable=str(self.integer), justify="center", width=4)
self.entry0.pack()
def plus_one(self):
x = self.integer.get() + 1
self.integer.set(x)
def take_one(self):
x = self.integer.get() - 1
self.integer.set(x)
def print_intvar(self):
print(self.integer.get())
app = Main()
app.mainloop()

You are watching: Python tkinter: How to make an Entry value update a variable?. Info created by GBee English Center selection and synthesis along with other related topics.