tkinter-输入对话框

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):
# get screen width and height
screen_width = self.winfo_screenwidth()
screen_height = self.winfo_screenheight()

# calculate position x and y coordinates
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()
# print("用户名:%s" % (self.solutionStr.get().strip()))


# 调用
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