在运行时更改对象的属性?
我有一个使用 Python 2.7 和 wxPython 的项目。我有 IDLE 和 Boa Constructor 作为 IDE。
我需要在运行时更改 GUI 对象(例如按钮)的一个或多个属性,尤其是大小、位置和文本(后者在按钮和标签中)。
如何在运行时更改这些属性?请注意,我将对大多数 GUI 对象使用绝对位置。
I have a project in Python 2.7 and wxPython. I have both IDLE and Boa Constructor available as IDEs.
I need to change one or more properties of a GUI object, such as a button, at run time - especially size, location, and text (the latter in buttons and labels).
How do I change these properties at run time? Mind you, I'll be using absolute position with most GUI objects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@JasonMc92,是的,绝对可以在应用程序中按需更改 wx 对象的属性(标签、大小、位置等)。您需要做的是阅读 wxPython 事件处理,以了解如何捕获单击按钮之类的操作,并添加指令以根据需要更改所需的属性。
您可以从他们的下载部分下载 wxPython 演示,其中包括大多数 wxPython 控件的工作示例必须提供。您还可以在此处查看wxPython的在线文档,以及新文档此处。您还可以查看本教程,了解有关 wxPython 事件处理的更多技术信息。我还记得 Boa Contructor 有自己的方法来在其接口中定义事件。我建议检查 Boa 提供的帮助和文档以获取更多信息。
@JasonMc92, Yes it is definitely possible to change a wx object's properties (labels, size, position, etc.) on demand within your application. What you need to do is read up on wxPython event handling to know how to catch actions like clicking a button and add your instructions to change your desired properties as required.
You can download the wxPython demo from their download section which includes working examples for the majority of the controls wxPython has to offer. You can also view wxPython's Online documentation here, and New documentation here. You can also check out this tutorial for more technical information regarding wxPython event handling. I can also recall that Boa Contructor has it's own methods for defining events within it's interface. I would suggest checking the provided help and documentation for Boa for further information.
更改小部件的标签或值很简单。如果您使用绝对定位,您可能可以更改小部件位置,但我认为这对用户来说是违反直觉的。我知道我不希望我的“关闭”按钮一直改变位置。我认为您可以使用其 SetSize() 方法设置大小,但这可能需要刷新。您自己实际尝试一下大约需要 10-15 分钟。
Changing the widget's label or value are simple things. You can probably change a widgets location if you are using absolute positioning, but I think that would be counter-intuitive for the user. I know I wouldn't want my Close button to change locations all the time. I think you can set the size using its SetSize() method, but that might require a refresh. It would take you about 10-15 minutes to actually try this yourself.