如何设置子窗口的标题

时间:2012-08-08 21:03:17

标签: python tkinter

我有以下代码:

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/的文档似乎有点过时,根本没有帮助。

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

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

1 个答案:

答案 0 :(得分:4)

使用.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()
相关问题