按钮生成(wx.Python,Python)

时间:2018-11-12 13:03:58

标签: python wxpython wxpython-phoenix

例如,我正在开发wxpython,我正在寻找生成按钮的方法。

  1. 在文本框中输入必须生成多少个按钮的值。

  2. 提交时,我必须在面板中显示与按钮一样多的

def __init__(self):
    wx.Frame.__init__(self, None, wx.ID_ANY, "Background Reset Tutorial",size=wx.Size(500,500))

    # Add a panel so it looks the correct on all platforms
    self.panel = wx.Panel(self, wx.ID_ANY)
    self.txt = wx.TextCtrl(self.panel,id=wx.ID_ANY,pos=(185,40))
    txtSizer = wx.BoxSizer(wx.HORIZONTAL)


    self.btn = wx.Button(self.panel,id=wx.ID_ANY,label="Submit",pos= 
               (190,70),size=(100,30))
    self.btn.Bind(wx.EVT_BUTTON,self.onSubmit)
def onSubmit(self,event):
    gettxt = self.txt.GetValue()

1 个答案:

答案 0 :(得分:0)

我找到了解决方法

def onBtn(self,event):

    self.val = self.txtstring1.GetValue()
    Blue = wx.Button(self,label="Blue",pos=(30,50))
    Blue.Bind(wx.EVT_BUTTON,self.onBlue)

    Green = wx.Button(self,label="Green",pos=(300,50))
    Green.Bind(wx.EVT_BUTTON,self.onGreen)
    for self.button_name in range(self.val):
        self.btn = wx.Button(self, label=str(self.button_name),pos=(50,50))
        self.btn.Bind(wx.EVT_BUTTON, lambda evt, temp=self.button_name: 
              self.OnButton(evt, temp))
        self.widgetSizer.Add(self.btn, 0, wx.ALL|wx.CENTER, 5)