Dear Mike,
Sorry for the confusion, I actually have read the wxPython tutorials, and here’s is a part of my gui.py
class PlanningFrame(wx.Frame):
def **__init__**(*self*, parent, title):
wx.Frame.__init__(*self*, parent, title=title, size=(2000,1000))
# change the frame background color
*self*.SetBackgroundColour(*"Silver"*)
# create some sizers
mainSizer = wx.BoxSizer(wx.VERTICAL)
grid = wx.GridBagSizer(hgap=5, vgap=5)
hSizer = wx.BoxSizer(wx.HORIZONTAL)
*self*.values = wx.StaticText(*self*, label=*"DEFAULT VALUES: "*)
grid.Add(*self*.values, pos=(0,0))
# add the submit button
*self*.button = wx.Button(*self*, label=*"Submit"*)
*self*.Bind(wx.EVT_BUTTON, *self*.OnClick,*self*.button)
# add standard deviation of the noise
*self*.sigma = wx.StaticText(*self*, label=*"Standard deviation of the noise: "*)
grid.Add(*self*.sigma, pos=(1,0))
*self*.edit_sigma = wx.TextCtrl(*self*, value=*"Ex: Sigma = 50"*, size=(150,-1))
grid.Add(*self*.edit_sigma, pos=(1,1))
# add some other text boxes...
...
...
def OnClick(self,e):
# Create a message dialog box
dlg = wx.MessageDialog(*self*, *"Information successfully submitted!"*, *"Result"*, wx.OK)
dlg.ShowModal() # Shows it
dlg.Destroy() # finally destroy it when finished.
app = wx.App(False)
frame = PlanningFrame(None, “Iterative Planning”)
frame.Show()
app.MainLoop()
My problem is, I want to be able to put my script.py and gui.py together, so that say the VARIABLE1 in my script.py takes on self.edit_sigma.GetValue()in my gui.py. I am hoping after clicking the submit button (my button now only returns a message box), my script.py will be executed and I will be able to display whatever result script.py give me in the message box.
Thank you,
Janey
···
On Mon, Jul 19, 2010 at 12:50 PM, Mike Driscoll mike@pythonlibrary.org wrote:
Hi Janey,
On Mon, Jul 19, 2010 at 2:38 PM, Janey Duong janey.duong@gmail.com wrote:
Hi there,
Thank you very much for your help, but I am still having hard time using the self.TextCtrl.GetValue()
Right now, I have 2 sets of python codes, say script.py and gui.py
In my script.py, I declared some global variables and wrote some functions as follow:
VARIABLE1 = 1
VARIABLE2 = 2
VARIABLE3 = 3
#====================
FUNCTIONS
#====================
def func1():
def func2():
def func3():
if name ==“main”:
func1()
func2()
funce()
In my gui.py, I have
class DemoFrame(wx.Frame):
def __init__(self, parent, title):
def OnClick(self):
When I tried to do VARIABLE1 = self.TextCtrl.GetValue(), I received an error that said name ‘self’ is not defined
Please help me to fix this error!
Thanks,
Janey
Have you read any of the tutorials on the wxPython website or wiki? Actually, you probably need to read through Dive Into Python or some other basic Introductory book on Python. Regardless, this code doesn’t run because you don’t instantiate anything. You aren’t starting a mainloop, creating a text control or a button or even binding the button to an event. I have attached a simple example though, which will hopefully clear up the confusion.
–
Mike Driscoll
Blog: http://blog.pythonlibrary.org
–
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en