我想创建一个弹出消息框,提示用户输入输入。我在一个类中有这个方法。我的代码基于java2s 的本指南。
class MyDialog:
def __init__(self, parent):
top = self.top = Toplevel(parent)
Label(top, text="Value").pack()
self.e = Entry(top)
self.e.pack(padx=5)
b = Button(top, text="OK", command=self.ok)
b.pack(pady=5)
def ok(self):
print "value is", self.e.get()
self.top.destroy()
root = Tk()
d = MyDialog(root)
root.wait_window(d.top)
但在这方面,top = self.top = Toplevel(parent)
对我不起作用。
我有一个我想要完成的模型。
我的程序结构如下所示:
class MainUI:
def__int__(self):
...
self.initUI()
def initUI(self):
.......
Popup = Button(self, text="Enter Value", command=self.showPopup)
def showPopup(self):
#create the popup with an Entry here
如何在 Python 中创建一个接受用户输入的消息框?