使用Python GUI创建按钮

use*_*917 0 python user-interface class tkinter button

我正在尝试使用类在Python中创建按钮,但在运行它时按钮不会出现.以下是我的代码

#Button_2
#Using Classes

from Tkinter import * 

class Application(Frame):
    """A GUI application with three button"""

    def _init_(self, master):
        """ Initialise the Frame. """
        Frame._init_(self, master)
        self.grid()
        self.create_widgets()

    def create_widgets(self):
        #"""Create three buttons"""
        #Create first buttom
        self.btn1 = Button(self, text = "I do nothing")
        self.btn1.grid()

        #Create second button
        self.btn2 = Button(self)
        self.btn2.grid()
        self.btn2.configure(text = "T do nothing as well")

        #Create third button
        self.btn3 = Button(self)
        self.btn3.grid()    
        self.btn3.configure(text = "I do nothing as well as well")

    root = Tk()
    root.title("Lazy Button 2")
    root.geometry("500x500")
    app = Application(root)

    root.mainloop()
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激

mgi*_*son 5

你需要命名你的"构造函数"方法__init__,而不是_init_.正如经上所记,你gridcreate_widgets方法永远不会因为所谓的_init_永远不会被调用.