好的,所以我正在玩弄并尝试了解如何使用按钮制作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()
答案 0 :(得分:1)
你不能让2 self.button
制作第二个self.button2
或其他东西