相关疑难解决方法(0)

使用Entry字段创建弹出消息框

我想创建一个弹出消息框,提示用户输入输入.我在一个类中有这个方法.我将我的代码基于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)
Run Code Online (Sandbox Code Playgroud)

但在这方面,top = self.top = Toplevel(parent)对我不起作用.

我有一个我想要完成的模型.

GUI样机

我的程序结构看起来像这样:

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
Run Code Online (Sandbox Code Playgroud)

如何在Python中创建一个接受用户输入的消息框?

python user-input tkinter

8
推荐指数
2
解决办法
6万
查看次数

标签 统计

python ×1

tkinter ×1

user-input ×1