pythontkinter应用程序中是否需要self关键字?

2024-05-29 01:39:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的代码,在没有将“self”添加到小部件实例的情况下,它似乎可以正常工作。如果我不使用自我,我会遇到问题吗?你知道吗

class Appy:

    def __init__(self, master):
        self.drawBoard()

    def drawBoard(self):
        pane_1 = ttk.PanedWindow(master, orient='horizontal')
        pane_1.pack(padx=20, pady=10, fill='both', expand=True)

        photo_frame = ttk.Frame()
        content_frame = ttk.Frame()

        pane_1.add(photo_frame)
        pane_1.add(content_frame)

        image_label = ttk.Label(photo_frame)
        image_label.pack(anchor='center', fill='both', expand=True)

        ....



if __name__ == '__main__':
    master = tkinter.Tk()
    Appy(master)
    master.geometry('1250x750+200+50')
    master.mainloop()

Tags: selfmastertruedeffillframepackexpand

热门问题