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()
好的發現我需要的只是需要添加self.Top.destroy() – Thomas
如果這是你的問題的答案,請創建一個自我回答。 – jensgram