简体   繁体   English

tkinter条目textvariable在Python 3中不显示

[英]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. 我有一个可以在Python 2.7中完美运行的GUI。 I recently updated to 3.5.2, and altered my tkinter imports appropriately, so it runs. 我最近更新到3.5.2,并适当地更改了我的tkinter导入,因此它可以运行。 However, none of the textvariable attributes of my Entry widgets are displaying. 但是,我的Entry小部件的textvariable属性都没有显示。 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. 我还尝试过在初始化后立即放置self.var.set(1.3)行,但是它不起作用。 Running this gives me an empty entry widget. 运行它会给我一个空的条目小部件。

I am running Python 3.5.2 in Enthought Canopy, using iPython 5.3.0 我正在使用iPython 5.3.0在Enthought Canopy中运行Python 3.5.2

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). 具体来说,当它为Pylab后端使用tk时(Preferences / Python中的选项)。 Switching it from tk eliminated the problem. 从tk切换可以消除此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM