2011-01-12 6 views
1

이것은 간단 해 보이지만 어떤 문서도 찾지 못했습니다. &&으로 시도해도 작동하지 않습니다. 이와 나를 위해wxpython에서 "&"버튼 텍스트를 쓰는 방법

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

이중 앰퍼샌드 '&&'가 단일 것으로 나타나지 않습니까? 내가 발견 한 모든 히트 곡은 그 곡이 그렇다는 것을 암시합니다. – MattH

+0

나는 작동하지 않는 것을 확인했다. – sagar

+0

내 질문은 메뉴 바를 클릭 이벤트로 표시 할 때 버튼 텍스트로 쓰는 것이어야한다. – sagar

답변

5

작품 :하십시오이 같은 버튼을 원하는

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() 
0

MattH하지만 내 문제를 작업에 코드가 사실은 내가 그 시간에 메뉴 바의 클릭 이벤트에서 버튼을 보여주는 & &되지 않은됩니다 작동합니다 ... 코드 아래에서 확인하십시오 ... 이런 경우에해야 할 일

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

@sagar : 올바르게 작동하는 형식의 코드를 게시하는 것이 도움이된다. 귀하의 모범은 나를 위해 잘 작동합니다. "시작"을 클릭하면 두 번째 버튼이 '버튼 & 2'로 나타납니다. – MattH

+0

내 측면에서 작동하지 않습니다. 첫 번째 버튼을 클릭 한 후 버튼 2에 튜너를 클릭하십시오. – sagar

+0

위의 정확한 코드를 실행 하시겠습니까? 또는 프로젝트의 일부입니까? – MattH

관련 문제