wxpython:按钮覆盖框架中的所有内容

时间:2013-11-05 09:34:58

标签: python wxpython

以下是我的代码:

#!/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()

实际上我希望框架上的button1看起来像一个按钮 - 有点凸起并放在框架的中心 - 但它只是扩展到整个框架。文本Button1看起来像一个没有按钮看起来像感觉的文本?

我做错了什么?

1 个答案:

答案 0 :(得分:1)

似乎创建一个面板(并将面板设置为父按钮)解决了问题(我增加了按钮宽度,以便您可以看到文本......)

#!/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()