class InputDlg(tk.Toplevel): def __init__(self): super().__init__() self.title('新方案名称') topFrame = tk.Frame(self) tk.Label(topFrame, text="方案名称:").pack(side=tk.LEFT) self.solutionStr = tk.StringVar() self.solutionEntry = ttk.Entry(topFrame, width=20, textvariable=self.solutionStr) self.solutionEntry.pack(side=tk.LEFT, padx=4) self.btnConfirm = tk.Button(topFrame, text="确定", command=self.on_btn_confirm).pack(side=tk.LEFT, padx=4)
topFrame.pack(side=tk.TOP, anchor='w') self.center_window(250, 100)
def center_window(self, width=1500, height=768): screen_width = self.winfo_screenwidth() screen_height = self.winfo_screenheight()
x = (screen_width / 2) - (width / 2) y = (screen_height / 2) - (height / 2) self.geometry('%dx%d+%d+%d' % (width, height, x, y))
def on_btn_confirm(self): self.quit() self.destroy()
self.isInputShow = False
if not self.isInputShow: self.isInputShow = True app = InputDlg() app.focus_set() app.solutionEntry.focus_set() self.wait_window(app) name = app.solutionStr.get().strip() print(name) self.isInputShow = False
|