代码之家  ›  专栏  ›  技术社区  ›  Joel Cornett Adrian

如何设置子窗口的标题

  •  1
  • Joel Cornett Adrian  · 技术社区  · 14 年前

    我有以下代码:

    from tkinter import *
    
    class MyApplication(Tk):
        def __init__(self):
            super().__init__()
            self.title = "Root Window"
            self.bind("<1>", self.showChild)
    
        def showChild(self):
            child = Toplevel(self)
            child.title = "This is the CHILD window"
    
    app = MyApplication()
    app.mainloop()
    

    子窗口的标题总是设置为 "Root Window" 。我不知道如何设置儿童窗口的标题。我也试过 child.wm_title = "This is the CHILD window" 但无济于事。文档位于 http://effbot.org/tkinterbook/ http://www.tkdocs.com/ 看起来有点过时,一点帮助都没有。

    如何将顶级小部件的标题设置为其主标题之外的其他内容??

    注意:我很确定这是无关紧要的,但我使用的是Python 3.2

    1 回复  |  直到 14 年前
        1
  •  4
  •   Honest Abe Cody Piersall    14 年前

    使用设置标题 .title() 方法
    而不是将其视为属性。

    import Tkinter as tk
    
    class MyApplication(tk.Tk):
        def __init__(self):
            tk.Tk.__init__(self)
            self.title("Root Window")
            self.bind("<1>", self.showChild)
    
        def showChild(self, event=None):
            self.top = tk.Toplevel(self)
            self.top.title("This is the CHILD window")
    
    app = MyApplication()
    app.mainloop()