点击按钮后如何得到子窗口?

2024-09-30 16:38:22 发布

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

请帮助修复脚本:

import tkinter


class Application(tkinter.Frame):

    def __init__(self, parent):
        tkinter.Frame.__init__(self, parent, bg='yellow')
        self.pack(side = 'top', fill = 'x')
        self.make_elements()

    def make_elements(self):
        tollbarFrame=tkinter.Frame(self)
        tollbarFrame.pack(side='top', fill='x')

        tool3=tkinter.Button(tollbarFrame, text='Add record', command=self.add_record())
        tool3.pack(side='left')


        contentFrame=tkinter.Frame(self)
        contentFrame.pack(side='top', fill='x')

        butt = tkinter.Button(contentFrame, text='qwerer')
        butt.pack()

    def add_record(self):
        child = tkinter.Toplevel()
        bu = tkinter.Button(child, text='sdfsf')
        bu.pack()


if __name__ == '__main__':
    root = tkinter.Tk()
    root.title('dvd list')
    root.geometry('700x500')
    Application(root)
    root.mainloop()

一旦你加载一个子窗口显示“子”。我对这个子窗口的想法应该在用户单击“添加记录”按钮后出现。你知道吗


Tags: textselfapplicationtkintertopdefbuttonroot