我正在尝试使用python为我的公司开发一个小型gui应用程序。有一个包含按钮的主窗口,这些按钮将根据需要启动更多窗口。子窗口之一包含Entry&Combobox窗口小部件,我希望在提交详细信息或关闭子窗口之前暂停执行。
主窗口代码
class SCInstaller():
def __init__(self, master):
#master.geometry("800x450+400+300")
self.content = ttk.Frame(master)
self.content.pack()
ttk.Button(self.content, text="CCR", command = ccr).grid(row = 0, column = 0,padx = 5, pady = 5)
ttk.Button(self.content, text="Reconciliation of Bank Statement", command = recon).grid(row = 0, column = 2, padx = 5, pady = 5)
ttk.Button(self.content, text="Customer Take-On", command = cust_takeon).grid(row = 1, column = 0, padx = 5, pady = 5)
ttk.Button(self.content, text="TBD", command = func4).grid(row = 1, column = 2, padx = 5, pady = 5)
#messagebox.showinfo(title = "Info", message = "The CCR has been generated")
if __name__ == "__main__":
root = Tk()
val = SCInstaller(root)
root.mainloop()
启动子窗口的代码
def newCI():
root = Toplevel()
new_customer = messagebox.askquestion(title = "New Customer", message = "Are there new customers to be added?")
if new_customer == "yes":
root.destroy()
logging.debug("YAY")
initCustomer() #has code to launch new window
logging.debug("Here")
#
#To develop an UI for entering a new customer - Probably a new function or continue here
else:
root.destroy()
logging.debug("NAY")
子窗口的代码
class ctakenon:
def __init__(self,root):
#code for entry and label widgets
#with buttons for submit, reset and cancel
def submit(self):
messagebox.showinfo(title="Submit", message="The details have been saved")
def cancel(self, root):
config.resp = messagebox.askquestion(title="Cancel", message= "Do you want to cancel")
if config.resp == "yes":
root.withdraw()
return
else:
pass
def on_closing(self, root):
config.resp = messagebox.askquestion("Quit", "Do you want to quit?")
if config.resp == "yes":
root.withdraw()
print("123")
def initCustomer():
logging.debug("Inside Customer Take On")
logging.debug(config.resp)
root = Toplevel()
ctakeon(root)
请原谅最后一部分中的巨大代码。它主要包括标签和条目。 单击子窗口中的提交按钮时,该信息将附加到全局变量,并且在取消时该窗口关闭。使用函数initCustomer()并立即执行该行,甚至在子窗口启动之前。
是否有一种方法可以暂停执行,直到添加了子窗口中的信息,即直到子窗口关闭为止。