Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python tkinter使用类保存小部件时的窗口标题_Python_Tkinter - Fatal编程技术网

Python tkinter使用类保存小部件时的窗口标题

Python tkinter使用类保存小部件时的窗口标题,python,tkinter,Python,Tkinter,我正在尝试向tkinter应用程序添加窗口标题。.title('Mytitle')在简单的示例中似乎可以很好地工作,但在我将小部件封装到类中的地方就不行了 下面是一个使用www.pythonware.com/library/tkinter/introduction中的“Hello,又来了”教程的简单示例/ 为什么这不起作用?谢谢 from Tkinter import * class App: def __init__(self, master): frame =

我正在尝试向tkinter应用程序添加窗口标题。.title('Mytitle')在简单的示例中似乎可以很好地工作,但在我将小部件封装到类中的地方就不行了

下面是一个使用www.pythonware.com/library/tkinter/introduction中的“Hello,又来了”教程的简单示例/

为什么这不起作用?谢谢

from Tkinter import *

class App:

    def __init__(self, master):

        frame = Frame(master)
        frame.pack()

        self.button = Button(frame, text="QUIT", fg="red", command=frame.quit)
        self.button.pack(side=LEFT)

        self.hi_there = Button(frame, text="Hello", command=self.say_hi)
        self.hi_there.pack(side=LEFT)

    def say_hi(self):
        print "hi there, everyone!"

root = Tk()

app = App(root)

root.title('blob')

root.mainloop()

根据Marcin Kowalczyk的评论,窗口太小,无法显示标题。奇怪的是,如果没有小部件,窗口将被扩展以显示标题,因此假设它实际上不在那里。

这似乎对我有用。您希望发生什么?请在设置标题后尝试实例化应用程序。不过,这对我来说似乎也很管用。它对我来说很管用,但很明显,在开始编写脚本后就看不到标题,因为窗口非常小。只有调整大小后才能看到它。您可以添加“root.geometry(“500x500”)”以使标题立即可见。是的,它正在工作,我的坏消息。谢谢你的检查!