2011-11-25 89 views
0

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

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() 
+0

好的发现我需要的只是需要添加self.Top.destroy() – Thomas

+1

如果这是你的问题的答案,请创建一个自我回答。 – jensgram

回答

1

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

相关问题