框架和Tkinter

时间:2014-07-06 13:36:47

标签: python class tkinter

我正在APOGEO的一本书上学习Python 3.x,Kenneth A. Lambert。 在一些练习中,我发现了一些错误(想想由于tkinter的一些变化)。

以下是示例:

from tkinter import *

class provaFinestra(Frame):

    def __init__(self):
        """Imposta finestra e suoi oggetti"""
        Frame.__init__(self)
        self.master.title("Finestra di Prova")
        self.grid()
        self._label = Label(self, text = "Ciao Mondo")
        self._label.grid()

    def main():
        """istanzia e visualizza la finestra"""
        wind = provaFinestra().mainloop

当我运行代码时,我收到以下错误:

the name 'provaFinestra' is not  defined.

我做错了什么

1 个答案:

答案 0 :(得分:1)

你应该把主要的课堂

from tkinter import *

class provaFinestra(Frame):

    def __init__(self):
        """Imposta finestra e suoi oggetti"""
        Frame.__init__(self)
        self.master.title("Finestra di Prova")
        self.grid()
        self._label = Label(self, text = "Ciao Mondo")
        self._label.grid()

def main():
    """istanzia e visualizza la finestra"""
    wind = provaFinestra().mainloop
main()