Need help in a script

Concept:
I am trying to write a program in which the Program will ask the User
a series of questions.

For example:

1. What is your name?

* The User inputs their name

* The User press enter

*Question number 1 disappears

*Another question appears

2. What is your age?

*User Inputs age

*The User press enter

***The program calculates

3. Outputs - "You have given me 2 pieces of information.

Specifically I do not know how to approach on making the Questions
disappear and then replaced.

username = wx.GetTextFromUser('What is your name?', 'Name?' )
    userage = wx.GenNumberFromUser('What is your age?', 'Age', 21, 0, 150)
    # Do your calculations here!
    ans = wx.MessgeBox('Hello %s\nYou have given me 2 pieces of
information.')

In a wx.PythonSimpleApp should do the job - take a look at the Demo code
in the wxPython docs and demo package.

Of course if you do not need dialogue boxes and just need to run from
the command prompt take a look at the python curses package - it should
give you just about all you are likely to need.

Gadget/Steve

···

On 20/06/2011 3:37 AM, just_vic8367 wrote:

Concept:
I am trying to write a program in which the Program will ask the User
a series of questions.

For example:

1. What is your name?

* The User inputs their name

* The User press enter

*Question number 1 disappears

*Another question appears

2. What is your age?

*User Inputs age

*The User press enter

***The program calculates

3. Outputs - "You have given me 2 pieces of information.

Specifically I do not know how to approach on making the Questions
disappear and then replaced.

Try something like this:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Mon Jun 20 06:54:49 2011

import wx

# begin wxGlade: extracode
# end wxGlade

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.label_1 = wx.StaticText(self, -1, "label_1")
        self.text_ctrl_1 = wx.TextCtrl(self, -1, "",
style=wx.TE_PROCESS_ENTER)

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_TEXT_ENTER, self.OnTextEnter,
self.text_ctrl_1)
        # end wxGlade

        self.questions = ['what is your name?', 'how old are you?']
        self.answers =
        self.qcount = 0
        self.label_1.SetLabel(self.questions[0])

    def __set_properties(self):
        # begin wxGlade: MyFrame.__set_properties
        self.SetTitle("Q & A")
        self.SetSize((640, 400))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame.__do_layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_1.Add(self.label_1, 0, 0, 0)
        sizer_1.Add(self.text_ctrl_1, 0, wx.EXPAND, 0)
        self.SetSizer(sizer_1)
        self.Layout()
        # end wxGlade

    def OnTextEnter(self, event): # wxGlade: MyFrame.<event_handler>
        self.qcount += 1
        try:
            self.answers.append(self.text_ctrl_1.GetValue())
            self.label_1.SetLabel(self.questions[self.qcount])
            self.text_ctrl_1.SetValue('')
        except:
            self.doCalculations()

        event.Skip()

    def doCalculations(self):
        print self.questions
        print self.answers

        for n in range(len(self.questions)):
          q = self.questions[n]
          try:
              a = self.answers[n]
              print 'q and a: %s = %s' % (q, a)
          except:
              print 'q and a: %s = (no answer)' % q

# end of class MyFrame

if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    frame_1 = MyFrame(None, -1, "")
    app.SetTopWindow(frame_1)
    frame_1.Show()
    app.MainLoop()

···

On Jun 19, 7:37 pm, just_vic8367 <vicp...@yahoo.com> wrote:

Concept:
I am trying to write a program in which the Program will ask the User
a series of questions.

For example:

1. What is your name?

* The User inputs their name

* The User press enter

*Question number 1 disappears

*Another question appears

2. What is your age?

*User Inputs age

*The User press enter

***The program calculates

3. Outputs - "You have given me 2 pieces of information.

Specifically I do not know how to approach on making the Questions
disappear and then replaced.

Thanks, that definitely points me in the right direction…

Vic

···

— On Mon, 6/20/11, jdawgaz jdawgaz@gmail.com wrote:

From: jdawgaz jdawgaz@gmail.com
Subject: [wxPython-users] Re: Need help in a script
To: “wxPython-users” wxpython-users@googlegroups.com
Date: Monday, June 20, 2011, 10:38 AM

Try something like this:

#!/usr/bin/env python

-- coding: utf-8 --

generated by wxGlade 0.6.3 on Mon Jun 20 06:54:49 2011

import wx

begin wxGlade: extracode

end wxGlade

class MyFrame(wx.Frame):
def init(self, *args, **kwds):
# begin wxGlade: MyFrame.init
kwds[“style”] = wx.DEFAULT_FRAME_STYLE
wx.Frame.init(self, *args, **kwds)
self.label_1 = wx.StaticText(self, -1, “label_1”)
self.text_ctrl_1 = wx.TextCtrl(self, -1, “”,
style=wx.TE_PROCESS_ENTER)

    self.__set_properties()
    self.__do_layout()

    self.Bind(wx.EVT_TEXT_ENTER, self.OnTextEnter,

self.text_ctrl_1)
# end
wxGlade

    self.questions = ['what is your name?', 'how old are you?']
    self.answers = []
    self.qcount = 0
    self.label_1.SetLabel(self.questions[0])

def __set_properties(self):
    # begin wxGlade: MyFrame.__set_properties
    self.SetTitle("Q & A")
    self.SetSize((640, 400))
    # end wxGlade

def __do_layout(self):
    # begin wxGlade: MyFrame.__do_layout
    sizer_1 = wx.BoxSizer(wx.VERTICAL)
    sizer_1.Add(self.label_1, 0, 0, 0)
    sizer_1.Add(self.text_ctrl_1, 0, wx.EXPAND, 0)
    self.SetSizer(sizer_1)

self.Layout()
# end wxGlade

def OnTextEnter(self, event): # wxGlade: MyFrame.<event_handler>
    self.qcount += 1
    try:
        self.answers.append(self.text_ctrl_1.GetValue())
        self.label_1.SetLabel(self.questions[self.qcount])
        self.text_ctrl_1.SetValue('')
    except:
        self.doCalculations()

    event.Skip()

def doCalculations(self):
    print self.questions
    print self.answers

    for n in range(len(self.questions)):
      q = self.questions[n]

try:
a = self.answers[n]
print ‘q and a: %s = %s’ % (q, a)
except:
print ‘q and a: %s = (no answer)’ % q

end of class MyFrame

if name == “main”:
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, “”)
app.SetTopWindow(frame_1)
frame_1.Show()
app.MainLoop()

On Jun 19, 7:37 pm, just_vic8367 <vicp…@yahoo.com> wrote:

Concept:
I am trying to write a program in which the Program will ask the User
a series of questions.

For
example:

  1. What is your name?
  • The User inputs their name

  • The User press enter

*Question number 1 disappears

*Another question appears

  1. What is your age?

*User Inputs age

*The User press enter

***The program calculates

  1. Outputs - "You have given me 2 pieces of information.

Specifically I do not know how to approach on making the Questions
disappear and then replaced.


To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Of course if you do not need dialogue boxes and just need to run from
the command prompt take a look at the python curses package - it should
give you just about all you are likely to need.
   

For something this simple, you don't even need curses -- a plain old command line and raw-input() will do it.

-Chris

I would assume that he will be dealing with users who have a deathly fear of or don’t know what to do with a command line.

I deal with those kind all the time. Some don’t even read what URL they are going to (DEV vs. PRODUCTION instances of webapps)!!!

Jerry

···

On Mon, Jun 20, 2011 at 11:39 AM, Chris Barker Chris.Barker@noaa.gov wrote:

Of course if you do not need dialogue boxes and just need to run from

the command prompt take a look at the python curses package - it should

give you just about all you are likely to need.

For something this simple, you don’t even need curses – a plain old command line and raw-input() will do it.

-Chris

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en


Licensed Amateur Radio Operator: K7AZJ

Registered Linux User: 275424

Recursion: (noun):
see: Recursion

A wx.wizard.Wizard would be another way to implement this.

···

On 6/19/11 7:37 PM, just_vic8367 wrote:

Concept:
I am trying to write a program in which the Program will ask the User
a series of questions.

For example:

1. What is your name?

* The User inputs their name

* The User press enter

*Question number 1 disappears

*Another question appears

2. What is your age?

*User Inputs age

*The User press enter

***The program calculates

3. Outputs - "You have given me 2 pieces of information.

Specifically I do not know how to approach on making the Questions
disappear and then replaced.

--
Robin Dunn
Software Craftsman