Python,使用wxPython从用户获取多个输入 [英] Python, Using wxPython to get multiple input from user

查看:419
本文介绍了Python,使用wxPython从用户获取多个输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题中,我发现了如何问用户使用wxPython进行输入.但是,我如何同时请求多个信息?

From this question I found out how to ask the user for an input using wxPython. But how can I ask for multiple information at the same time?

基本上,我想创建一个消息框,其中每个输入框下面都有三个输入字段,询问名称",姓氏",昵称".我还希望代码非常简单,例如:

Basicly I want to create a message box with three input fields under each other asking for "Name" "Surname" "Nickname". I also want to have the code really simple like:

name,surname,nick = askInfo("Name","Surname","Nickname")

它不一定是wxPython,但一定不要使用Tkinter.

It doesn't have to be wxPython but it MUST not be using Tkinter.

推荐答案

构建wx.Dialog那里有很多示例.

import wx
class MyFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1, "Dialog Test",size=(500,400))
        self.panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.log = wx.TextCtrl(self.panel, wx.ID_ANY, size=(400,300),style = wx.TE_MULTILINE|wx.TE_READONLY|wx.VSCROLL)
        self.button = wx.Button(self.panel, label="Click me")
        sizer.Add(self.log, 0, wx.EXPAND | wx.ALL, 10)
        sizer.Add(self.button, 0, wx.EXPAND | wx.ALL, 10)
        self.panel.SetSizer(sizer)
        self.Bind(wx.EVT_BUTTON, self.OnButton)

    def OnButton(self,event):
        dlg = GetData(parent = self.panel) 
        dlg.ShowModal()
        if dlg.result_name:
            self.log.AppendText("Name: "+dlg.result_name+"\n")
            self.log.AppendText("Surname: "+dlg.result_surname+"\n")
            self.log.AppendText("Nickname: "+dlg.result_nickname+"\n")
        else:
            self.log.AppendText("No Input found\n")
        dlg.Destroy()

class GetData(wx.Dialog):
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent, wx.ID_ANY, "Name Input", size= (650,220))
        self.panel = wx.Panel(self,wx.ID_ANY)

        self.lblname = wx.StaticText(self.panel, label="Name", pos=(20,20))
        self.name = wx.TextCtrl(self.panel, value="", pos=(110,20), size=(500,-1))
        self.lblsur = wx.StaticText(self.panel, label="Surname", pos=(20,60))
        self.surname = wx.TextCtrl(self.panel, value="", pos=(110,60), size=(500,-1))
        self.lblnick = wx.StaticText(self.panel, label="Nickname", pos=(20,100))
        self.nickname = wx.TextCtrl(self.panel, value="", pos=(110,100), size=(500,-1))
        self.saveButton =wx.Button(self.panel, label="Save", pos=(110,160))
        self.closeButton =wx.Button(self.panel, label="Cancel", pos=(210,160))
        self.saveButton.Bind(wx.EVT_BUTTON, self.SaveConnString)
        self.closeButton.Bind(wx.EVT_BUTTON, self.OnQuit)
        self.Bind(wx.EVT_CLOSE, self.OnQuit)
        self.Show()

    def OnQuit(self, event):
        self.result_name = None
        self.Destroy()

    def SaveConnString(self, event):
        self.result_name = self.name.GetValue()
        self.result_surname = self.surname.GetValue()
        self.result_nickname = self.nickname.GetValue()
        self.Destroy()

app = wx.App()
frame = MyFrame(None)
frame.Show()
app.MainLoop()

要特别注意result

这篇关于Python,使用wxPython从用户获取多个输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆