WxPython-按钮>;文本输入窗口>;新面板中的输出
我想单击一个按钮,显示一个“文本输入框”,然后打印按钮所在的原始面板中键入的值 我设法让按钮+框工作,但我不知道如何在面板中显示值 我对这一切都很陌生:) 代码如下:WxPython-按钮>;文本输入窗口>;新面板中的输出,wxpython,Wxpython,我想单击一个按钮,显示一个“文本输入框”,然后打印按钮所在的原始面板中键入的值 我设法让按钮+框工作,但我不知道如何在面板中显示值 我对这一切都很陌生:) 代码如下: import wx class st3000(wx.Frame): def __init__(self,parent,id): wx.Frame.__init__(self,parent,id,'title', size=(353,270)) panel=wx.Panel(self)
import wx
class st3000(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'title', size=(353,270))
panel=wx.Panel(self)
button1=wx.Button(panel,label='something',pos=(10,10),size=(-1,60))
button2=wx.Button(panel,label='anything', pos=(150,10),size=(-1,60))
button3=wx.Button(panel,label='nothing', pos=(250,10),size=(-1,60))
self.Bind(wx.EVT_BUTTON, self.opcao1, button1)
self.Bind(wx.EVT_BUTTON, self.opcao2, button2)
self.Bind(wx.EVT_BUTTON, self.opcao3, button3)
self.Bind(wx.EVT_CLOSE, self.closewindow)
def opcao1(self,event):
box1=wx.TextEntryDialog(None,'Type...','','...here')
if box1.ShowModal()==wx.ID_OK:
answer1=box1.GetValue()
output=wx.StaticText(panel,-1,answer1,(10,80),(260,-1),wx.ALIGN_CENTER)
output.SetForegroundColour('red')
output.SetBackgroundColour('blue')
def opcao2(self,event):
self.Close(True)
def opcao3(self,event):
self.Close(True)
def closewindow(self,event):
self.Destroy()
if __name__=='__main__':
app=wx.PySimpleApp()
frame=st3000(parent=None,id=-1)
frame.Show()
app.MainLoop()
这里的问题是,一旦到达“init”方法的末尾,panel对象就超出了范围,因此不能在“opcao1”方法中使用它。如果在代码中引用“panel”的地方用“self.panel”替换“panel”,那么它将按预期工作。“self”使变量成为类属性