Programmer
Programmer

Reputation: 8727

wxpython : button covers all in the frame

Below is my code:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import wx

class Example(wx.Frame):

    def __init__(self):
        #super(Example, self).__init__(parent, title=title, size=(300, 200))
        wx.Frame.__init__(self, None, wx.ID_ANY, 'wxButton', pos=(300, 150), size=(320, 250))
        self.button1 = wx.Button(self, id=-1, label='Button1', pos=(8, 8), size=(10, 20))
        self.button1.Bind(wx.EVT_BUTTON, self.button1Click)
        self.Centre()
        self.Show()


    def button1Click(self,event):
        #self.button1.Hide()
        self.SetTitle("Button1 clicked")

if __name__ == '__main__':

    app = wx.App()
    Example()
    app.MainLoop()

Actually I am expecting the button1 on the frame to have a look like a button - a bit raised and be placed in center of frame - but it is just expanding to the full frame. Also text Button1 looks like a text which does not has a button look like feeling?

What wrong am I doing?

Upvotes: 1

Views: 78

Answers (1)

jbat100
jbat100

Reputation: 16827

It seems creating a panel (and setting the panel as the button parent) solves the problem (I've increased the button width so that you can see the text...)

#!/usr/bin/python
# -*- coding: utf-8 -*-

import wx

class Example(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, 'wxButton', pos=(300, 150), size=(320, 250))
        self.panel = wx.Panel(self, -1)
        self.button1 = wx.Button(self.panel, id=-1, label='Button1', pos=(8, 8), size=(100, 20))
        self.button1.Bind(wx.EVT_BUTTON, self.button1Click)
        self.Centre()
        self.Show()

    def button1Click(self,event):
        self.SetTitle("Button1 clicked")

if __name__ == '__main__':

    app = wx.App()
    Example()
    app.MainLoop()

Upvotes: 1

Related Questions