Python wx按钮单击其中一个按钮时,仅显示一个按钮的对话框

Python wx按钮单击其中一个按钮时,仅显示一个按钮的对话框,python,button,user-interface,wxpython,Python,Button,User Interface,Wxpython,好的,我正在玩游戏,试图了解如何使用按钮制作GUI,我想我应该从简单开始,使用两个按钮制作一个GUI,根据单击的按钮显示不同的消息。我做了第一个按钮并测试了它。。。工作很好,做了第二个按钮,当我测试它时,当我点击第一个按钮时,我得到了第二个按钮的消息,当我点击第二个按钮时,什么都没有。我试着四处搜索,但似乎没有其他人有这个问题,所以我显然做错了什么 #!/usr/bin/env python import os import wx class Frame(wx.Frame): def

好的,我正在玩游戏,试图了解如何使用按钮制作GUI,我想我应该从简单开始,使用两个按钮制作一个GUI,根据单击的按钮显示不同的消息。我做了第一个按钮并测试了它。。。工作很好,做了第二个按钮,当我测试它时,当我点击第一个按钮时,我得到了第二个按钮的消息,当我点击第二个按钮时,什么都没有。我试着四处搜索,但似乎没有其他人有这个问题,所以我显然做错了什么

#!/usr/bin/env python
import os
import wx

class Frame(wx.Frame):

    def OnOpen(self,e):
        self.dirname=''
        dlg=wx.FileDialog(self,'Choose a File',self.dirname,'','*.*',wx.OPEN)

        if dlg.ShowModal()==wx.OK:
            self.filename=dlg.GetFileName()
            self.dirname=dlg.GetDirectory()
            f=open(os.path.join(self.dirname,self.filename),'r')
            self.Control.SetValue(f.read())
            f.close()
            dlg.Destroy()

    def OnAbout(self,e):
        dlg=wx.MessageDialog(self,'Aoxx','Author',wx.OK)
        dlg.ShowModal()
        dlg.Destroy()

    def OnExit(self,e):
        dlg=wx.MessageDialog(self,'Exit','Terminate',wx.OK)
        dlg.ShowModal()
        self.Close(True)
        dlg.Destroy()

    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,'Frame works',size=(450,600))
        panel=wx.Panel(self)

        self.CreateStatusBar()

        filemenu=wx.Menu()
        self.filemenu=wx.Menu()
        menubar=wx.MenuBar()
        menubar.Append(filemenu,'&File')
        #menubar.Append(filemenu,'&Help')
        self.SetMenuBar(menubar)

        MenuOpen=filemenu.Append(wx.ID_OPEN,'&Open','File Dir')
        MenuExit=filemenu.Append(wx.ID_ANY,'E&xit','Term')
        MenuAbout=filemenu.Append(wx.ID_ABOUT,'&About','Info')

        self.Bind(wx.EVT_MENU,self.OnOpen,MenuOpen)
        self.Bind(wx.EVT_MENU,self.OnExit,MenuExit)
        self.Bind(wx.EVT_MENU,self.OnAbout,MenuAbout)



        pic1=wx.Image('C:\Users\******\Pictures\Tri.bmp', wx.BITMAP_TYPE_BMP).ConvertToBitmap()
        self.button=wx.BitmapButton(panel,-1, pic1,pos=(10,10))
        self.Bind(wx.EVT_BUTTON,self.ClickTri,self.button)
        self.button.SetDefault()

        pic2=wx.Image('C:\Users\******\Pictures\ClickWin.bmp', wx.BITMAP_TYPE_BMP).ConvertToBitmap()
        self.buton=wx.BitmapButton(panel,-1,pic2,pos=(220,10))
        self.Bind(wx.EVT_BUTTON,self.ClickWin,self.button)


    def ClickTri(self,event):
        dlg=wx.MessageDialog(self,'No touching the TriForce Rook!','HEY!!!',wx.OK)
        dlg.ShowModal()
        dlg.Destroy()       

    def ClickWin(self,event):
        dlg=wx.MessageDialog(self,'You would.....','REALLY?',wx.OK)
        dlg.ShowModal()
        dlg.Destroy()

        self.Show(True)

if __name__=='__main__':
    app=wx.PySimpleApp()
    frame=Frame(None,id=-1)
    frame.Show()
    app.MainLoop()

你不能有2个
self.button
做第二个
self.button2
或其他什么东西如果我想让按钮打开一个新的框架,我需要在该框架下定义另一个类吗?exp
def ClickTri(self,event):类Frame2(wx.Frame):…
这取决于您想要什么。。。您可能需要在某个地方定义一个新的框架。。。尽管不是在click事件中,但是您可以执行
def OnClick(self,evt):f2=SomeOtherFrame();f2.Show()