sorry, “file” was a slip of the pen,I changed it to dialoga, but can't
popup window either when I clicked button,
error message:TypeError: OpenFile() takes no arguments (2 given)
import wx
class TopFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, "My first GUI APP", size=
(200, 100))
self.panel = wx.Panel(self, -1)
self.panel.SetBackgroundColour("White")
self.buttona = wx.Button(self.panel, -1, label="Open File",
style=wx.BU_LEFT)
self.Bind(wx.EVT_BUTTON, self.OpenFile, self.buttona)
def OpenFile():
dialoga = wx.FileDialog(None, message="Choose a file",
defaultDir="", defaultFile="", wildcard="*.*", style=wx.OPEN,
pos=wx.DefaultPosition)
if dialoga.ShowModal() == wx.ID_OK:
print dialoga.GetPath()
dialoga.Destroy()
def OnButtonClick(self, event):
self.panel.SetBackgroundColour('Green')
self.panel.Refresh()
def main():
app = wx.PySimpleApp()
frame = TopFrame(parent=None, id=-1)
frame.Show()
app.MainLoop()
if __name__ == '__main__':
main()
···
On Jun 1, 8:03 am, Josh English <joshua.r.engl...@gmail.com> wrote:
You are assigning "file = wx.FileDialog(...)" but referring to "if
dialog.ShowModal() ==..."
Use "dialog" instead of "file" as your variable. file is a reserved
word in Python, I think.
Josh
On 5/31/09, Mike Driscoll <m...@pythonlibrary.org> wrote:
> Hi,
> On Sun, May 31, 2009 at 4:35 AM, guoguo <999...@gmail.com> wrote:
> > I want to popup a sole file-select window as I click a button, I
> > searched it in the email list, nothing was found. Here is my code,
> > thank in advance
> > import wx
> > class TopFrame(wx.Frame):
> > def __init__(self, parent, id):
> > wx.Frame.__init__(self, parent, id, "My first GUI APP", size=
> > (200, 300))
> > self.panel = wx.Panel(self, -1)
> > self.panel.SetBackgroundColour("White")
> > self.buttona = wx.Button(self.panel, -1, label="Open File",
> > style=wx.BU_LEFT)
> > self.Bind(wx.EVT_BUTTON, self.OpenFile, self.buttona)
> > def OpenFile():
> > file = wx.FileDialog(None, message="Choose a file",
> > defaultDir="", defaultFile="", wildcard="*.*", style=wx.OPEN,
> > pos=wx.DefaultPosition)
> > if dialog.ShowModal() == wx.ID_OK:
> > print dialog.GetPath()
> > dialog.Destroy()
> > def OnButtonClick(self, event):
> > self.panel.SetBackgroundColour('Green')
> > self.panel.Refresh()
> > def main():
> > app = wx.PySimpleApp()
> > frame = TopFrame(parent=None, id=-1)
> > frame.Show()
> > app.MainLoop()
> > if __name__ == '__main__':
> > main()
> So what is the problem exactly? The code looks like it should work to me.
> - Mike
--
Josh English
Joshua.R.Engl...@gmail.comhttp://joshenglish.livejournal.com