Reputation: 121
I have quick question about tkinter Python. I created Button added command to execute some function, but how to make, that after clicking button and function execution window would close.
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()
Upvotes: 0
Views: 2920
Reputation: 385970
To destroy the main window you would call the destroy
method of that window object. In your case it would be self.Top.destroy()
if you want to destroy self.Top
.
Upvotes: 1