简体   繁体   English

wxPython在运行时创建控件

[英]wxPython create controls at runtime

i want to create a class that create control at runtime; 我想创建一个在运行时创建控件的类; for example: 例如:

self.Text1 = wx.TextCtrl( self.m_panel1, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size( 50,-1 ), wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB )
self.Text1.SetFont( wx.Font( 12, 74, 90, 90, False, wx.EmptyString ) )

Tranform this (for Example define my ipotetic library) on 转换此(例如定义我的ipotetic库)

AddText(Text1, self.m_panel1, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size( 50,-1 ), wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB )
self.Text1.SetFont( wx.Font( 12, 74, 90, 90, False, wx.EmptyString ) )

It's possibible to create and accessing to control at runtime? 在运行时创建和访问控件是否可行?

Thank's Aesis. 谢谢你的Aesis。

I actually wrote an article on this topic a while back which you can read here: 我实际上写了一篇关于这个主题的文章,你可以在这里阅读:

The idea is to create the widget and then call the parent's Layout() method to get it to show up correctly. 我们的想法是创建窗口小部件,然后调用父窗体的Layout()方法使其正确显示。 If you're going to be adding a lot of widgets, then you might want to use a ScrolledPanel or similar, otherwise the widgets may get added off-screen. 如果您要添加大量小部件,那么您可能希望使用ScrolledPanel或类似小部件,否则小部件可能会在屏幕外添加。

Binding dynamic widgets is tricky in that you want to define the event handlers BEFORE you create the widgets. 绑定动态小部件非常棘手,因为您希望在创建小部件之前定义事件处理程序。 I don't have any examples handy. 我没有任何方便的例子。 However, you might get some ideas from this article for one approach: 但是,您可以从本文中获得一些方法的一些想法:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM