开发者

How to write a "&" in button text in wxpython

Thi开发者_JAVA技巧s looks simple but I have not found any documentation. Tried with &&, which does not work. Want a button like this:

Button1=wx.Button(self, 5, "abc&abc", (130, 230))


Works for me with this:

import wx

class MainWindow(wx.Frame):
  def __init__(self,parent,title):
    wx.Frame.__init__(self,parent,title=title,size=(200,-1))
    self.sizer = wx.BoxSizer(wx.HORIZONTAL)
    self.buttons = [
      wx.Button(self,-1,"Button &One"),
      wx.Button(self,-1,"Button &&Two"),
    ]
    for btn in self.buttons:
      self.sizer.Add(btn,1,wx.EXPAND)
    self.SetSizer(self.sizer)
    self.SetAutoLayout(1)
    self.sizer.Fit(self)
    self.Show()

app = wx.App(False)
frame = MainWindow(None,"Hello Ampersand")
app.MainLoop()


Your code working MattH but my problem is actually i was showing button in click event of menubar at that time && not works..check out below code...what should be done in such a case

import wx

class MainWindow(wx.Frame):
  def __init__(self,parent,title):     
    wx.Frame.__init__(self,parent,title=title,size=(699, 570))     

    fileMenu= wx.Menu()
    folder=wx.MenuItem(fileMenu, 1, "&Start","Click here to start..")

    fileMenu.AppendItem(folder)
    about = wx.MenuItem(fileMenu, 2, '&About',"Test")

    fileMenu.AppendItem(about)
    quit = wx.MenuItem(fileMenu, 3, '&Quit',"Terminate the program")

    fileMenu.AppendItem(quit)
    menuBar = wx.MenuBar()
    menuBar.Append(fileMenu,"&File")    
    self.Bind(wx.EVT_MENU, self.ShowButton, folder)

    self.SetMenuBar(menuBar)     
    pndSummaryButton = wx.Button(self, 3, "Button &&Two", (130, 146))
    pndSummaryButton.name="pndSummary"

    self.printArea2 = wx.TextCtrl(self,pos = (290, 146), size = (255, 25),style = wx.TE_READONLY)
    pndSummaryButton.SetFont(wx.Font(11, wx.SWISS, wx.NORMAL,wx.LIGHT))
    self.printArea2.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL,wx.LIGHT))
    pndSummaryButton.SetBackgroundColour(wx.Colour(153,0,0))
    pndSummaryButton.SetForegroundColour(wx.Colour(255,255,255))
    pndSummaryButton.SetSize(pndSummaryButton.GetBestSize())

    self.Show()  

  def ShowButton(self,event):
    pndSummaryButton = wx.Button(self, 3, "Button &&Two", (130, 176))
    pndSummaryButton.name="pndSummary1"
    self.printArea2 = wx.TextCtrl(self,pos = (290, 176), size = (255, 25),style = wx.TE_READONLY)
    pndSummaryButton.SetFont(wx.Font(11, wx.SWISS, wx.NORMAL,wx.LIGHT))
    self.printArea2.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL,wx.LIGHT))
    pndSummaryButton.SetBackgroundColour(wx.Colour(153,0,0))
    pndSummaryButton.SetForegroundColour(wx.Colour(255,255,255))
    pndSummaryButton.SetSize(pndSummaryButton.GetBestSize())

app = wx.App(False) 
frame = MainWindow(None,"Hello Ampersand") 
app.MainLoop() 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜