2016-08-20 6 views
0

私はwxPythonサウンドボードを作成していて、About Boxを実装する方法が不思議でした。目的は、wxPythonの[ファイル]メニューの[バージョン情報]ボタンを押してAboutボックスを生成することです。wxPython:aboutボックスを追加する。

これは、これまでの私のコードです:

import wx 
import os 
import pygame 

pygame.init() 

##SOUNDS## 
goliathwav = pygame.mixer.Sound("goliath.wav") 
channelopen = pygame.mixer.Sound("channelopen.wav") 
##SOUNDS## 


class windowClass(wx.Frame): 
    def __init__(self, *args, **kwargs): 
     super(windowClass,self).__init__(*args,**kwargs) 
     self.__basicGUI() 
    def __basicGUI(self): 
     panel = wx.Panel(self) 
     menuBar = wx.MenuBar() 
     fileButton = wx.Menu() 
     editButton = wx.Menu() 
     aboutBox = wx.MessageDialog(None, "Created by  Kommander000(cyrex)") 
     answer=aboutBox.ShowModal() 
     aboutBox.Destroy() 
     aboutButton = wx.Menu() 
     exitItem = fileButton.Append(wx.ID_EXIT, 'Exit','status msg...') 
     aboutItem = aboutButton.Append(wx.ID_ABOUT, "About") 



     menuBar.Append(fileButton, 'File') 
     menuBar.Append(editButton, 'Edit') 
     menuBar.Append(aboutButton, 'About this program') 

     self.SetMenuBar(menuBar) 
     self.Bind(wx.EVT_MENU, self.__quit, exitItem) 
     self.Bind(wx.EVT_MENU, self.OnMenuHelpAbout, aboutBox) 

     self.__sound_dict = { "Goliath" : "goliath.wav", 
           "Goliath2" : "channelopen.wav" 
          } 

     self.__sound_list = sorted(self.__sound_dict.keys()) 

     self.__list = wx.ListBox(panel,pos=(20,20), size=(250,150)) 
     for i in self.__sound_list: 
      self.__list.Append(i) 
     self.__list.Bind(wx.EVT_LISTBOX,self.__on_click) 

     #wx.TextCtrl(panel,pos=(10,10), size=(250,150)) 

     self.SetTitle("Soundboard") 
     self.Show(True) 

    def __on_click(self,event): 
     event.Skip() 
     name = self.__sound_list[self.__list.GetSelection()] 
     filename = self.__sound_dict[name] 
     if filename == "goliath.wav": 
      print "[ NOW PLAYING ] ... %s" % filename 
      pygame.mixer.Sound.play(goliathwav) 
     if filename == "channelopen.wav": 
      print "[ NOW PLAYING ] ... %s" % filename 
      pygame.mixer.Sound.play(channelopen) 


    def __quit(self, e): 
     self.Close() 
def main(): 
    app = wx.App() 
    windowClass(None, -1, style=wx.MAXIMIZE_BOX | wx.CAPTION | wx.CENTRE) 
    app.MainLoop() 

main() 

は、これは私が受けていますエラーです:

self.Bind(wx.EVT_MENU, self.OnMenuHelpAbout, aboutBox) 
AttributeError: 'windowClass' object has no attribute 'OnMenuHelpAbout' 

任意の提案ですか?再びいつものように

おかげで、

kommander000

答えて

0

あなたは:)

aboutBoxは(私は私の前の回答で述べたようにプライベートにするためにリファクタリングすることを)あなたの行方不明のコールバックOnMenuHelpAboutで作成する必要があります

また、私は辞書を変更してサウンドオブジェクトを直接指し示すようにしました:これ以上のコードはありません。if/elif同じ。

固定コード:

import wx 
import os 
import pygame 

pygame.init() 

##SOUNDS## 
##SOUNDS## 


class windowClass(wx.Frame): 
    __goliathwav = pygame.mixer.Sound("goliath.wav") 
    __channelopen = pygame.mixer.Sound("channelopen.wav") 

    def __init__(self, *args, **kwargs): 
     super(windowClass,self).__init__(*args,**kwargs) 
     self.__basicGUI() 
    def __basicGUI(self): 
     panel = wx.Panel(self) 
     menuBar = wx.MenuBar() 
     fileButton = wx.Menu() 
     editButton = wx.Menu() 
     aboutButton = wx.Menu() 
     exitItem = fileButton.Append(wx.ID_EXIT, 'Exit','status msg...') 
     aboutItem = aboutButton.Append(wx.ID_ABOUT, "About") 



     menuBar.Append(fileButton, 'File') 
     menuBar.Append(editButton, 'Edit') 
     menuBar.Append(aboutButton, 'About this program') 

     self.SetMenuBar(menuBar) 
     self.Bind(wx.EVT_MENU, self.__quit, exitItem) 
     self.Bind(wx.EVT_MENU, self.__onmenuhelpabout, aboutItem) 

     self.__sound_dict = { "Goliath" : self.__goliathwav, 
           "Goliath2" : self.__channelopen 
          } 

     self.__sound_list = sorted(self.__sound_dict.keys()) 

     self.__list = wx.ListBox(panel,pos=(20,20), size=(250,150)) 
     for i in self.__sound_list: 
      self.__list.Append(i) 
     self.__list.Bind(wx.EVT_LISTBOX,self.__on_click) 

     #wx.TextCtrl(panel,pos=(10,10), size=(250,150)) 

     self.SetTitle("Soundboard") 
     self.Show(True) 

    def __onmenuhelpabout(self,event): 
     event.Skip() 
     aboutBox = wx.MessageDialog(None, "Created by  Kommander000(cyrex)") 
     answer=aboutBox.ShowModal() 
     aboutBox.Destroy() 

    def __on_click(self,event): 
     event.Skip() 
     name = self.__sound_list[self.__list.GetSelection()] 
     sound = self.__sound_dict[name] 
     print("[ NOW PLAYING ] ... %s" % name) 
     pygame.mixer.Sound.play(sound) 


    def __quit(self, e): 
     self.Close() 
def main(): 
    app = wx.App() 
    windowClass(None, -1, style=wx.MAXIMIZE_BOX | wx.CAPTION | wx.CENTRE) 
    app.MainLoop() 

main() 
    def __quit(self, e): 
     self.Close() 
def main(): 
    app = wx.App() 
    windowClass(None, -1, style=wx.MAXIMIZE_BOX | wx.CAPTION | wx.CENTRE) 
    app.MainLoop() 

main() 
+0

をちょっとちょっと支援のための私の男のおかげで。私は助けが必要なときに誰に電話するか知っています。ありがとう、もう一度男、 – kommander0000

+1

私は良いpythonの本やチュートリアルをお勧めしたいと思います。私はいつも周りにいるわけではありません。 –

2

WXパイソンはwx.AboutDialogInfo()

def About(self, event): 
    from platform import platform 
    myos = platform() 
    aboutInfo = wx.AboutDialogInfo() 
    aboutInfo.SetName("My Application ") 
    aboutInfo.SetVersion("1.0") 
    aboutInfo.SetDescription("My Super App," \ 
     " That does amazing things\nRunning on: "+myos) 
    aboutInfo.SetCopyright("(C) Joe Bloggs-2016") 
    aboutInfo.SetLicense("https://www.gnu.org/licenses/gpl-2.0.html") 
    aboutInfo.AddDeveloper("Joe Bloggs") 
    aboutInfo.AddDocWriter("Joe Bloggs") 
    aboutInfo.SetWebSite('https://www.JoeBlogs.com') 
    wx.AboutBox(aboutInfo) 

と組み合わせて使用​​し、独自のwx.AboutBox()を持って参照してください。https://wxpython.org/docs/api/wx-module.html#AboutBox

関連する問題