python - 想着特质。动态更新 GUI 中的列表
问题描述
好的。所以我一直遇到这个障碍,我无法根据我正在做的事情来更新 GUI。我进行了广泛的搜索并尝试阅读,但我几乎无所适从。我得到的最接近的是从“myclass.uncorrex_thing”中删除该项目,然后运行“edit_traits”,但这只会在旧的 GUI 上创建一个新的 GUI...
摘要:我从 .csv 中获取了一个文件名列表,其中有很多每天都在变化的项目。我只想能够从 GUI 上的列表中选择文件名,按下对文件执行某些操作的按钮并从 .csv 列表中检查该文件名,然后使用更新的 .csv 更新 GUI 上的下拉列表
到目前为止,这是我的代码
class My_List(HasTraits):
tracker = RecordKeeping()
uncorrex_items = tracker.get_uncorrected_list() #this creates a list of filenames based on a .csv file
uncorrex_items.insert(0,'Select file')
class DataFrameEditorDemo(HasTraits):
err_correct = PostProcessAutoErrorCorrection() #a separate module for correcting the files
myclass = Instance(My_List)
highlighted_thing = Str
Calc = Button('Run Corrections')
traits_view = View(
Item('Calc', label='correct file'),
Item("highlighted_thing", editor= EnumEditor(name = 'object.myclass.uncorrex_items')),
title="MyEditor"
)
def _Calc_fired(self):
if len(self.highlighted_thing) == 8:
self.err_correct.correct_form(self.highlighted_thing) #this corrects the file selected from the dropdown list
#AND it updates the .csv file so the file should be checked as complete and will not show up when "tracker.get_uncorrected_list()" is run again
解决方案
好的,对于任何看到这个并想知道的人,我终于解决了我的问题。基本上必须创建一个取决于事件(按下按钮)的属性类。当按下按钮时,highlighted_thing
更新和更正表单并更新 .csv 的功能运行
class DataFrameEditorDemo(HasTraits):
err_correct = PostProcessAutoErrorCorrection() #a separate module for correcting the files
tracker = RecordKeeping() #a separate module for managing the .csv
highlighted_thing = Property(List, depends_on = 'Calc')
test = Str
Calc = Button('Run Corrections')
traits_view = View(
Item('Calc', label='correct file'),
Item("test", editor= EnumEditor(name = 'highlighted_thing')),
title="MyEditor"
)
def _get_highlighted_thing(self):
return tracker.get_uncorrected_list()
def _Calc_fired(self):
if len(self.test) == 8:
self.err_correct.correct_form(self.test)
推荐阅读
- npm - 终端卡住,npm install 后无法输入 git 命令
- python - 如何在pycharm中清除屏幕
- c# - 不支持使用 let 关键字的 Entity Framework Core 5?
- css - RStudio Connect 在更新时将 CSS 粘贴到单元格中
- c++ - OpenCL 内核删除所需的时间
- android - Android Studio 出现 Google Pay 错误,我该如何解决?
- variables - 在版本中更新变量组变量
- variables - JavaFX:为 EventHandler(时间轴)正确链接变量
- arrays - 角度数组对象选择特定元素
- google-sheets - 有没有办法将值从谷歌表格工作簿绘制到 tradingview pinescript?