我对python很新,我试图用npyscreen组合一个小应用程序。此应用程序的一部分有一个带有FormControlBox的页面,在选中时会显示一个FormControlBox。第二个FormControlBox在选中后会显示一些文本字段。
我遇到的问题是如果未选择第一个FormControlBox将其值更改为False(使第二个隐藏)。以下是我尝试参加此表单类的方法。
class envMenuForm(npyscreen.Form):
def afterEditing(self):
# Updating mapping with values set from form creation
hostConfig["hostname"] = self.hostname.value
hostConfig["domain"] = self.domain.value
hostConfig["fqdn"] = self.fqdn.value
self.parentApp.setNextForm('CEV')
def create(self):
# Defining vars from current baseConfig mapping from JSON file
self.hostname = hostConfig["hostname"]
self.domain = hostConfig["domain"]
self.fqdn = hostConfig["fqdn"]
# Adding text fields with the defaults from the config file
self.hostname = self.add(npyscreen.TitleText, name = "System Hostname:", value = self.hostname)
self.domain = self.add(npyscreen.TitleText, name = "System Domain:", value = self.domain)
self.fqdn = self.add(npyscreen.TitleText, name = "System Fully Qualified Domain Name:", value = self.fqdn)
self.et0status = self.add(npyscreen.FormControlCheckbox, name="Enable Eth0", value = False)
self.et0type = self.add(npyscreen.FormControlCheckbox, name = "Configure as Static Address (ignore for DHCP)", value = False)
self.et0ipaddress = self.add(npyscreen.TitleText, name = "IP Address", value = "127.0.0.1")
self.et0status.addVisibleWhenSelected(self.et0type)
self.et0type.addVisibleWhenSelected(self.et0ipaddress)
def while_editing(self,arg):
if arg is self.et0type:
if arg.hidden:
self.et0type.value = False
答案 0 :(得分:0)
经过一系列的重构后,我能够利用adjust_widgets()和一些背景逻辑来解决这个问题,以确保它不会发生太大的事情。