TKinter Python窗口在按下按钮后关闭

时间:2011-11-25 08:09:06

标签: python button tkinter

我有关于tkinter Python的快速提问。我创建了Button添加命令来执行某些功能,但是如何制作,单击按钮后,功能执行窗口就会关闭。

def Top(self):
    self.string1=StringVar()  ###
    self.string2=StringVar()  
    self.string3=StringVar()  ###
    self.Top=Toplevel()
    self.Top.title("Database Preferences")
    L1=Label(self.Top, text="Host")
    L1.pack(side=TOP)
    self.entry1=Entry(self.Top, textvariable=self.string1)
    self.entry1.pack(side=TOP, padx=10, pady=12)
    L2=Label(self.Top, text="User")
    L2.pack(side=TOP)
    self.entry2=Entry(self.Top, textvariable=self.string2)
    self.entry2.pack(side=TOP, padx=10, pady=12)
    L3=Label(self.Top, text="Pass")
    L3.pack(side=TOP)
    self.entry3=Entry(self.Top, textvariable=self.string3)
    self.entry3.pack(side=TOP, padx=10, pady=12)
    Button(self.Top, text="ok", command=self.createini).pack(side=BOTTOM, padx=10, pady=10)



def createini(self):
    cfgfile = open("conf.ini",'w')
    self.Config = ConfigParser.ConfigParser()
    self.Config.add_section('Database')
    self.Config.set('Database',"host", self.string1.get())
    self.Config.set('Database',"user", self.string2.get())
    self.Config.set('Database',"pass", self.string3.get())
    self.Config.write(cfgfile)
    cfgfile.close()

1 个答案:

答案 0 :(得分:1)

要销毁主窗口,您可以调用该窗口对象的destroy方法。在您的情况下,如果您要销毁self.Top.destroy(),则为self.Top

相关问题