1
這看起來很簡單,但我還沒有找到任何文檔。試用&&
,這是行不通的。希望這樣的按鈕:如何在wxpython中編寫按鈕文本中的「&」
Button1=wx.Button(self, 5, "abc&abc", (130, 230))
這看起來很簡單,但我還沒有找到任何文檔。試用&&
,這是行不通的。希望這樣的按鈕:如何在wxpython中編寫按鈕文本中的「&」
Button1=wx.Button(self, 5, "abc&abc", (130, 230))
工作對我來說這一點:
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()
您的代碼工作MattH但我的問題其實我是顯示在菜單欄的點擊事件按鈕當時& &不works..check下面的代碼...在這種情況下應該做什麼
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()
你確定雙&符號`&&`不顯示爲一個單一?我發現的所有命中都表明它確實如此。 – MattH 2011-01-12 10:54:34
我已檢查不工作.. – sagar 2011-01-12 11:00:28