Ironpython:如何使第二个Combobox依赖于第一个

时间:2020-10-13 10:00:30

标签: python combobox ironpython

我正在通过winforms在Ironpython 2.7中创建一个接口。

我想创建两个comboboxex,第二个必须依赖第一个。这意味着如果我在第一个组合中具有值“ Default”,则数据源必须在第二个组合框中为[3,4],否则为[1,2]

我已经用ifelse进行了尝试,但是它不起作用,因为第二个组合框中始终有相同的数据源

有什么想法可以解决这个问题吗?

我的代码是下一个

import clr

clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
import System

from System.Windows.Forms import *
from System.Drawing import *

# Create a class form
class CreateWindow(Form):
    def __init__(self):
        #Create the form_
        self.Name = "Daniel Alejandre Pérez | BIM Nodes"
        self.Text = "Daniel Alejandre Pérez | BIM Nodes"
        self.Size = Size(500, 400)
        self.CenterToScreen()
        self.values = []
        
        #Create label for Combobox1
        labelCombobox1 = Label(Text = "Selecciona el tipo de tubería")
        labelCombobox1.Parent = self
        labelCombobox1.Location = Point(30,20)
        labelCombobox1.Width = 150
        
        #Combobox
        self.Combobox1 = ComboBox()
        self.Combobox1.Parent = self
        self.Combobox1.DataSource = ["Default","IBV Geberit Mepla ML_TW","IBV_Geberit PE-HD_GL+RW","IBV_Geberit Silent-PP_SW","IBV_Mapress St-Steel_HZ","Stahl Nahtlos"]
        self.Combobox1.Location = Point(200,20)
        self.Combobox1.Width = 200
        
        #Create labe for sheet number
        labelSheetNumber = Label(Text = "Selecciona el diámetro de la tubería")
        labelSheetNumber.Parent = self
        labelSheetNumber.Location = Point(30,50)
        labelSheetNumber.Width = 200
    
        #Create Textbox for Sheet Number
        self.textboxSheetNumber = TextBox()
        self.textboxSheetNumber.Parent = self
        self.textboxSheetNumber.Text = ""
        self.textboxSheetNumber.Location = Point(250,50)
        self.textboxSheetNumber.Width = 150
    
        #Create label for sheet name
        labelPowered = Label(Text = "v0.1 09/10/2020 | Powered by BIM Nodes")
        labelPowered.Parent = self
        labelPowered.Location = Point(195,120)
        labelPowered.Width = 400
        
        
        
        self.Combobox2 = ComboBox()
        self.Combobox2.Parent = self
        if self.Combobox1.Text=="Default":
            self.Combobox2.DataSource = ["3","4"]
        else:
            self.Combobox2.DataSource = ["1","2"]
        self.Combobox2.Location = Point(30,200)
        self.Combobox2.Width = 200
        
        #Create button
        button = Button()
        button.Parent = self
        button.Text = "Ok"
        button.Location = Point(325,90)
        #Register Event
        button.Click += self.ButtonClicked
    
    def ButtonClicked(self, sender, args):
        if sender.Click:
            self.values.append(self.textboxSheetNumber.Text)
            self.values.append(self.Combobox1.Text)
            self.Close()
            

if IN[0]:
    form = CreateWindow()
    Application.Run(form)

    OUT = form.values

0 个答案:

没有答案