2011-01-12 3 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番目のボタンが「ボタンと2」と表示されます。 – MattH

+0

それは私の側で働いていません。ボタン2にフレームの最初のボタンをクリックした後もtunrs。 – sagar

+0

上記の正確なコードを実行していますか?あなたのプロジェクトの一部ですか? – MattH

関連する問題