使用 wxPython 获取用户输入 [英] Using wxPython to get input from user
本文介绍了使用 wxPython 获取用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我需要用 wxPython 对话框替换以下代码中的 raw_input
函数,该对话框要求用户输入并将值返回给程序:
Suppose I need to replace the raw_input
function in the following code with a wxPython dialog box that asks for user input and returns the value to program:
...
x = raw_input("What's your name?")
print 'Your name was', x
...
我只是在寻找一种简单的方法来做到这一点.谢谢
I'm just looking for a simple way to do that. Thanks
推荐答案
这是另一种简单的方法,可以满足我的要求:
Here is another simple way that does what I was looking for:
import wx
def ask(parent=None, message='', default_value=''):
dlg = wx.TextEntryDialog(parent, message, defaultValue=default_value)
dlg.ShowModal()
result = dlg.GetValue()
dlg.Destroy()
return result
# Initialize wx App
app = wx.App()
app.MainLoop()
# Call Dialog
x = ask(message = 'What is your name?')
print 'Your name was', x
这篇关于使用 wxPython 获取用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文