1

I have this simple Dialog:

import wx  
import wx.lib.sized_controls as sc  
import time  
import datetime  
class Dialog(sc.SizedDialog):  
    def __init__(self, parent, id):  
        sc.SizedDialog.__init__(self, None, -1, "AuTel", style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)            
        pane = self.GetContentsPane()  
        pane.SetSizerType("form")  

        wx.StaticText(pane, -1, "N1:")
        N1_BOX = wx.SpinCtrl(pane, -1, "", (40,40), (60,-1))
        N1_BOX.SetRange(1,1000)
        N1_BOX.SetValue(2)

        wx.StaticText(pane, -1, "N2:")
        N2_BOX = wx.SpinCtrl(pane, -1, "", (40,40), (60,-1))
        N2_BOX.SetRange(1,1000)
        N2_BOX.SetValue(10)

        wx.StaticText(pane, -1, "T1:")
        T1_BOX = wx.SpinCtrl(pane, -1, "", (40,40), (60,-1))
        T1_BOX.SetRange(1,60)
        T1_BOX.SetValue(4)

        wx.StaticText(pane, -1, "T2:")
        T2_BOX = wx.SpinCtrl(pane, -1, "", (40,40), (60,-1))
        T2_BOX.SetRange(1,60)
        T2_BOX.SetValue(5)

        RUN_BUTTON = self.SetButtonSizer(self.CreateStdDialogButtonSizer(wx.OK | wx.CANCEL))

        self.Fit()
        self.SetMinSize(self.GetSize())

app = wx.PySimpleApp()
dlg = Dialog(None, -1)
dlgrslt = dlg.ShowModal()

if dlgrslt != wx.ID_OK:
print ('Exiting..')
exit
else:
    pass
    print (N1+N2/T1-T2)

dlg.Destroy()
app.MainLoop()

I need when I click OK, Values of N1_BOX, N2_BOX, T1_BOX, and T2_BOX to be taken, then I can use them later in the script for other purpose. What shall I do in my script in order to achieve this ? Also, how can I make another Window to display the result of N1+N2/T1-T2 ? I need this window to be attached with the dialog window, but i don't know how can I do it. Sorry for my basic questions, but I am new to programing world.

Regards, Amr

1 Answer 1

4

1: Accessing input values

The most basic way is to make each 'box' a member of your class.

i.e. wherever you write N1_BOX, put 'self.N1_BOX'.

So, in your calling code, you can access dlg.N1_BOX.GetValue()

valX = dlg.N1_BOX.GetValue()+dlg.N2_BOX.GetValue() / dlg.T1_BOX.GetValue()+dlg.T2_BOX.GetValue()
print valX

2: The 'result dialog':

Create a second class, say ResultDialog, with an extra parameter in the init method. You can then pass in your new value into this extra parameter.

So, say you had set the valX variable, then you can pass it in like so:

dlg2= ResultDialog(None,-1,str(valX))

Note the use of str() to convert the valX number for presentation on a label. This could be done inside the init method, but I put it here as a hint.

HTH

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.