简单的对话框多任务处理

时间:2017-10-05 20:37:35

标签: python tkinter simpledialog

如何在tkinter中的单个simpledialogbox中询问字符串和整数问题而不打开另一个simpledialogbox

from tkinter import *
from tkinter import simpledialog

simpledialog. askstring("name", "what is your name ")
Mainloop()

1 个答案:

答案 0 :(得分:0)

您可以使用Toplevel()创建自己的simpledialog版本,如下所示:

from tkinter import *

class App:
    def __init__(self, root):
        self.root = root
        self.button1 = Button(self.root, text="Ok", command=self.drawtop)
        self.button1.pack()
    def drawtop(self):
        self.top = Toplevel(root)
        self.entry1 = Entry(self.top)
        self.entry2 = Entry(self.top)
        self.button2 = Button(self.top, text="Done", command=self.printtop)
        self.entry1.pack()
        self.entry2.pack()
        self.button2.pack()
    def printtop(self):
        print(self.entry1.get())
        print(self.entry2.get())
        self.top.destroy()

root = Tk()
App(root)
root.mainloop()