Search code examples
pythonpython-3.xtkintertkinter-entry

tkinter entry textvariable not displaying in Python 3


There have been similar questions asked, but none reflect the behavior I am seeing. I have a GUI that was working perfectly in Python 2.7. I recently updated to 3.5.2, and altered my tkinter imports appropriately, so it runs. However, none of the textvariable attributes of my Entry widgets are displaying. The values are stored properly, just not displaying. Here is a minimal example:

import tkinter as tk
class App:
    def __init__(self,window):
        self.root = window
        self.var = tk.DoubleVar()
        self.entry = tk.Entry(self.root,textvariable=self.var)
        self.var.set(1.3)
        self.entry.pack()
main = tk.Tk()
App(main)
main.mainloop()

I have also tried putting the self.var.set(1.3) line immediately after the initialization, but it doesn't work. Running this gives me an empty entry widget.

I am running Python 3.5.2 in Enthought Canopy, using iPython 5.3.0


Solution

  • As alluded to in the comments, this turned out to be a Canopy problem. Specifically, when it uses tk for the Pylab backend (option in Preferences/Python). Switching it from tk eliminated the problem.