0

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

from tkinter import *
from tkinter import simpledialog

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

1 回答 1

0

您可以使用Toplevel()创建自己的 a 版本,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()
于 2017-10-06T15:35:18.180 回答