在Python中编码时没有出现的按钮

时间:2017-09-11 16:45:16

标签: python class button tkinter

我对Python有点新手,目前通过在线视频学习。当我遇到问题时,我正在编写这段代码:没有按钮出现。对于视频中的人来说似乎工作正常,所以我想知道我做错了什么。

请记住,这是来自视频教程,因此代码可能不是那么好。

如果有帮助,我正在使用PyCharm Community Edition 2017.2。

事先,谢谢!

from tkinter import *


class Application(Frame):
    def ___init___(self, master):
        Frame.__init__(self, master)
        self.grid()
        self.create_widgets()

    def create_widgets(self):
        self.button1 = Button(self)
        self.button1.grid()
        self.button1.configure(text="Button1")
        self.button2 = Button(self, text="Button 2")
        self.button2.grid()
        self.button3 = Button(self, text="Button 3")
        self.button3.grid()

root = Tk()
root.title("Something")
root.geometry("200x100")

app = Application(root)

root.mainloop()

1 个答案:

答案 0 :(得分:2)

您使用了错误的__init__功能,它在之前/之后只需要2个下划线:

class Application(Frame):
    def __init__(self, master):
        Frame.__init__(self, master)
        self.grid()
        self.create_widgets()