Hello all!
I have a panel:
class TrafficPane(wx.Panel):
Initializer
the class constructor
def init(self, parent, msgq):
wx.Panel.init(self,
parent)
self.msgq = msgq
open a file named “logfile.txt”
in “a” append mode;
creates file if it doesn’t exist.
self.logfile =
open(‘logfile.txt’, ‘a’)
#layout of the panel. 10 px gap
on each side of TextCtrls. panel is a grid,
#texctrls and lables are placed
at grid positions like (1,1), (2,1) etc.
sizer =
wx.GridBagSizer(hgap=10, vgap=10)
defines a dictionary ({} = empty
dictionary), to hold the text control values
self.fields = {}
#TextCtrl recipe:
#creates the first label static text
on gui panel
label = wx.StaticText(self, -1,
“DUID:”)
#position on the gui panel
grid, top left
sizer.Add(label, pos=(1,1))
#create the textCtrl field,
give it a size, make it read-only
field = wx.TextCtrl(self, -1,
“”, size=(144, -1), style=wx.TE_READONLY)
#sticks TextCrtl to grid right
of label
sizer.Add(field, pos=(1,2))
#add the field for this
TextCtrl to the dictionary
self.fields[“duid”] =
field;
There are 8 more TextCtrls like this
one. I need to put an event button under the TextCtrls that will
trigger the wxFileDialog something like:
def openfile(self, event):
dlg = wx.FileDialog(self,
“Choose a file”, os.getcwd(), “”, “.”,
wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
mypath =
os.path.basename(path)
self.SetStatusText(“You
selected: %s” % mypath)
dlg.Destroy()
This is to allow the user to open/choose a logfile from the UI. This has got to be one of the most common
pieces of code a person will need but I have been having real trouble
find some standard pieces of code to do this.
Thanks in advance!