首页 > 解决方案 > Tkinter 代码未显示按钮 (v:3.6)

问题描述

这是我在 youtube 上的练习,它没有在窗口中显示按钮

import tkinter as tk
class Window(Frame):
    def _init_ (self, master =None):
        Frame.__init__(self, master)

        self.master = master
        self.init_window()
    def init_window(self):
        self.master.title('GUI')
        self.pack(fill = BOTH, expand = 1)
        quitButton = Button(self, text = "Quit")
        quitButton.place(x=0, y =.1)

root = tk.Tk()

root.title('GUI')
root.geometry()
app = Window(master=root)
root.mainloop()

标签: pythontkinter

解决方案


只需将您更改_init___init__. Python 构造函数语法有双下划线。

__INIT__在 Python 类中理解自我和方法。

__init__是 python 类中的一种保留方法。它在面向对象的概念中被称为构造函数。当从类创建对象时调用此方法,它允许类初始化类的属性。


推荐阅读