【问题标题】:Local variable have value '.!toplevel.!calendar.!frame' on VARIABLES section visual studio code when debugging python code调试 python 代码时,局部变量在 VARIABLES 部分 Visual Studio 代码中具有值 '.!toplevel.!calendar.!frame'
【发布时间】:2019-08-08 04:14:39
【问题描述】:

在这个项目中,我想为自己的目的自定义tkcalendar python。 当我逐行跟踪时,我想知道在第 420 行哪些是来自 tkinter 的常见 ttk.Frame 设置了 self.header 类属性。 self.header 对象现在具有 _w 键对象,其中包含我什至不知道其含义的值。

我想知道我红色下划线的这个值格式的含义。

感谢您的帮助。

【问题讨论】:

    标签: python debugging tkinter visual-studio-code


    【解决方案1】:

    Tkinter 是嵌入式 tcl/tk 解释器的包装器。每个 tkinter 小部件都与较低级别的 tcl/tk 小部件相关联。 _w 属性是这个低级 tcl/tk 小部件的名称。

    tcl/tk 小部件的命名约定类似于文件系统路径,不同之处在于它使用. 而不是/。因此,根窗口是前导.,后续子窗口由. 分隔。 Tcl 允许您使用您想要的任何字符作为名称,. 除外。

    在最新版本的 tkinter 中,tkinter 通过将小部件类转换为小写字母并在其前面加上 ! 来选择名称。如果已经有一个同名的小部件,它会附加一个数字(例如:.!frame.!frame2 等)

    您的具体示例如下所示:

    .!toplevel.!calendar.!frame
    ^^         ^         ^
    ||         |         +- Frame widget, child of the Calendar
    ||         +-Calendar widget, child of the Toplevel
    |+-Toplevel widget, child of the root window
    +-root window 
    

    虽然很少这样做,但您可以提供自己的小部件名称,以使这个内部名称更有意义。考虑这个例子:

    root = tk.Tk()
    dialog = tk.Toplevel(root, name="custom-dialog")
    buttons = tk.Frame(dialog, name="button-frame")
    ok = tk.Button(buttons, name="ok-button")
    

    使用上面的代码,“确定”按钮将具有以下内部名称:

    .custom-dialog.button-frame.ok-button 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-04
      • 1970-01-01
      • 2018-09-26
      相关资源
      最近更新 更多