[WxPython] Nothing is showing on my frame?

Post here if you need help with creating a Graphical User Interface in Python.

[WxPython] Nothing is showing on my frame?

Postby Xiaoqing Zhao » Sun Aug 04, 2013 10:53 am

Code: Select all
#!usr/bin/env python

import wx

class InsertFrame(wx.Frame):
    def _init_(self,parent,id):
        wx.Frame.__init__(self,parent,id,'Frame With Button',size=(300,100))
        panel=wx.Panel(self)
        button=wx.Button(panel,label="close",pos=(125,10),size=(50,50))
        self.Bind(wx.EVT_BUTTON,self.OnCloseMe,button)
        self.Bind(wx.EVT_CLOSE,self.OnCloseWindow)
   
    def OnCloseMe(self,event):
        self.Close(True)

    def OnCloseWindow(self,event):
        self.Destroy()


if __name__=='__main__':
    app=wx.PySimpleApp()
    frame=InsertFrame(parent=None,id=-1,title='Frame With Button')
    frame.Show()
    app.MainLoop()


I don't understand no button on the form.
Please tell me the correct code!
Last edited by Yoriz on Sun Aug 04, 2013 11:14 am, edited 1 time in total.
Reason: changed title
Xiaoqing Zhao
 
Posts: 2
Joined: Fri Aug 02, 2013 11:28 am

Re: About wxPython

Postby Yoriz » Sun Aug 04, 2013 11:12 am

Hi welcome to the forum
Your init is not correct, you have only single _ when they should be double, this means nothing is getting initialised.
Code: Select all
def _init_(self,parent,id):

Should be
Code: Select all
def __init__(self,parent,id):

Also note that you will get another error due to the following line
Code: Select all
frame=InsertFrame(parent=None,id=-1,title='Frame With Button')

you are passing in a title argument but your init method does not expect it
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 842
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: [WxPython] Nothing is showing on my frame?

Postby Xiaoqing Zhao » Sun Aug 04, 2013 11:46 am

Thank you very much!
According to what you said,I've got the correct results.
Xiaoqing Zhao
 
Posts: 2
Joined: Fri Aug 02, 2013 11:28 am

Re: [WxPython] Nothing is showing on my frame?

Postby Vik2015 » Tue Sep 03, 2013 5:22 pm

Btw, it is better to use wx.App, not wx.PySimpleApp
Vik2015
 
Posts: 21
Joined: Sat May 18, 2013 8:53 pm
Location: Computer


Return to GUI

Who is online

Users browsing this forum: No registered users and 2 guests