Python 2.7 如何使用组合框选择在同一对话框中插入计算?

Python 2.7 如何使用组合框选择在同一对话框中插入计算?,python-2.7,wxpython,Python 2.7,Wxpython,我在wxPython中创建了一个对话框,其中包含从下拉列表中选择的组合框。一旦我从组合框中选择了一个值,然后(按下“应用”选项卡),我想用它来填充同一对话框中的其他字段。是否有任何类似的例子或任何建议来实现它将是有益的 以下是我所拥有的: import wx class MyFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'Segment Generator', siz

我在wxPython中创建了一个对话框,其中包含从下拉列表中选择的组合框。一旦我从组合框中选择了一个值,然后(按下“应用”选项卡),我想用它来填充同一对话框中的其他字段。是否有任何类似的例子或任何建议来实现它将是有益的

以下是我所拥有的:

import wx    

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'Segment Generator', size=(580, 500))
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        panel = wx.Panel(self, -1)

        text1.SetForegroundColour((255,0,0)) # set text color
        SegList = ['1','2','3']
        self.Soil = wx.ComboBox(panel, -1, "", (115, 45), wx.DefaultSize, SegList, wx.CB_DROPDOWN)

        wx.StaticBox(panel, -1, "Create/Update Segment", (15, 90), size=(250,290))


        wx.StaticBox(panel, -1, "Quick Merge", (30, 120), size=(220,120))
        wx.StaticText(panel, -1, "Single Overland", (100, 150))
        cb1 = wx.CheckBox(panel, -1, '', pos=(70,150))
        wx.StaticText(panel, -1, "Single Swale", (100, 180))
        cb2 = wx.CheckBox(panel, -1, '', pos=(70,180))
        wx.StaticText(panel, -1, "Single Channel", (100, 210))
        cb3 = wx.CheckBox(panel, -1, '', pos=(70,210))

        wx.StaticBox(panel, -1, "Merge Specific Segment", (30, 250), size=(220,110))
        wx.StaticText(panel, -1, "Upstream Pixel #", (40, 280))
        self.uspixel = wx.TextCtrl(panel, -1, value="", pos=(170, 275), size=(65,25))
        wx.StaticText(panel, -1, "Downstream Pixel #", (40, 315))
        self.dspixel = wx.TextCtrl(panel, -1, value="", pos=(170, 310), size=(65,25))

        wx.StaticBox(panel, -1, "Method Statistics", (300, 80), size=(240,300))
        wx.StaticText(panel, -1, "Seg #", (320, 105))
        wx.StaticText(panel, -1, "Overall Tc (hrs):", (320, 140))
        self.sanumber = wx.TextCtrl(panel, -1, value="", pos=(455, 135), size=(75,25), style = wx.TE_READONLY) # overall Tc hrs
        wx.StaticText(panel, -1, "Overland Tc (hrs):", (320, 175))
        self.sanumber = wx.TextCtrl(panel, -1, value="", pos=(455, 170), size=(75,25), style = wx.TE_READONLY) # overland Tc hrs
        wx.StaticText(panel, -1, "Swale Tc (hrs):", (320, 210))
        self.sanumber = wx.TextCtrl(panel, -1, value="", pos=(455, 205), size=(75,25), style = wx.TE_READONLY) # swale Tc hrs
        wx.StaticText(panel, -1, "Channel Tc (hrs):", (320, 245))
        self.sanumber = wx.TextCtrl(panel, -1, value="", pos=(455, 240), size=(75,25), style = wx.TE_READONLY) # channel Tc hrs
        wx.StaticText(panel, -1, "# Overland Segments:", (320, 280))
        self.sanumber = wx.TextCtrl(panel, -1, value="", pos=(455, 275), size=(75,25), style = wx.TE_READONLY) # overland segments
        wx.StaticText(panel, -1, "# Swale Segments:", (320, 315))
        self.sanumber = wx.TextCtrl(panel, -1, value="", pos=(455, 310), size=(75,25), style = wx.TE_READONLY) # swale segments
        wx.StaticText(panel, -1, "# Channel Segments:", (320, 350))
        self.sanumber = wx.TextCtrl(panel, -1, value="", pos=(455, 345), size=(75,25), style = wx.TE_READONLY) # channel segments

        self.btnApply = wx.Button(panel, label="Recalculate Tc", pos=(360, 35))
        self.Bind(wx.EVT_BUTTON, self.OnSet, id=self.btnApply.GetId())

        self.btnApply = wx.Button(panel, label="Close Dialog", pos=(450, 400))
        self.Bind(wx.EVT_BUTTON, self.OnClose, id=self.btnApply.GetId())

        self.btnApply = wx.Button(panel, label="Apply", pos=(100, 400))
        self.Bind(wx.EVT_BUTTON, self.OnApply, id=self.btnApply.GetId())

        self.Show(True)
        self.Centre(True)

    def OnSet(self, event):
        self.Show(True)

    def OnApply(self, event):
        # some calculations to fill fields created during initialization
        self.Show(True)

    def OnClose(self, event):
        self.Show(False)

在OnApp处理程序中,检查组合框的内容,然后在其他控件中相应地设置值,如下所示:

def OnApply(self, event):
    soilValue = self.Soil.GetValue()
    if soilValue == 1:
        self.uspixel.SetValue('something')
        # set values for other controls
    elif soilValue == 2:
        # set values
    elif soilValue == 3:
        # set values
    else:
        # clear all values
顺便说一句,你为什么多次打电话给self.Show(True)?在init方法中执行就足够了