python - wxpython : button covers all in the frame

标签 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()

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

我做错了什么?

最佳答案

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

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

关于python - wxpython : button covers all in the frame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19785681/

相关文章:

python - 在 IIS 5.1 上设置 Python

python - Python获取多个Button点击事件的方法

wxpython - ListCtrl - wxPython 获取列中的所有值

python - 如何使用Python 3.3.2在Windows XP上运行wxPython 2.9.4?

python - 是否可以隐藏网格中的特定列?

python - wxPython ListCtrl 列忽略特定字段

python - 在 BeautifulSoup 4.7.0+ 中,如何选择在其属性之一中不包含指定文本的所有元素

python - Django - 将 URL "name"属性传递给 View

python - Tkinter askcolor 返回错误的 RGB 值?

python - wxPython:从文件绘制基于矢量的图像