1

下面是我的代码:

#!/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 看起来像文字,没有按钮的感觉?

我在做什么错?

4

1 回答 1

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()
于 2013-11-05T09:50:24.937 回答