python - 在程序运行开始时填充 wxChoice | Python

标签 python populate wxwidgets wxformbuilder

一旦我的程序运行,我希望我的 wxChoice 被我指定的列表中的项目填充。我正在使用 wxFormBuilder 来处理程序的 GUI 元素。

我的代码:

    def onDropDownSelection(self, parent):

    #Open designated file 
    lines = tuple(open("/Users/it/Desktop/Classbook/masterClassList.txt", 'r'))

    #Strips the first line of the file, splits the elements, assigns to "one"
    lines[1].rstrip()
    one = lines[1].split("|")

    #My attempt to populate the wxChoice with my list "one"
    self.firstChoice.SetItems(one)

当用户单击下拉(wxChoice)菜单时激活此事件,并在每次单击时重新填充。

有没有一种方法可以在程序首次打开/运行时填充我的 wxChoice,仅一次?

我已将此代码放置在创建 wxChoice 的位置。但是,我现在在第 44 行遇到“取消缩进与任何外部缩进级别不匹配”的情况。如何解决此问题?

enter image description here

最佳答案

检查您的缩进。有时如果你复制粘贴,这可能会把事情搞砸。 只需重写它或用其他语句替换它即可。看这里: IndentationError: unindent does not match any outer indentation level

问题是,如果您使用制表符进行缩进,然后从示例页面复制粘贴一些代码,其中缩进是使用空格进行的。然后你就有了混合的缩进。我已经经历过很多次了。

关于python - 在程序运行开始时填充 wxChoice | Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27625215/

相关文章:

python - 在 python 中将字符串作为 FORMDATA 发布

python - 如何使用坐标通过辛普森规则计算多边形的面积?

php - 使用 PHP 和 MySQL 查询的简单交叉表

c++ - 在代码块中找不到 -lwxmsw30u_core 和 -lwxbase30u

c++ - netbeans 项目的发布构建和调试构建

java - 如何知道 https 服务器是单向 ssl 还是双向 ssl

python - Monkey-patch 用于单元测试的内置函数?

javascript - 使用 javascript 填充多个字段

node.js - 填充时连接字符串

python - wx.ListBox.HitTest 在 Mac 上不工作