在 wxPython 中使用 sizer 来布置我的表单时遇到了一些挑战,如果有人能让我开始布置我的表单,如图所示,我将不胜感激。
请分享来源。
谢谢
最佳答案
在设计复杂的 gui 时,我不会手动使用 sizer。只是,请使用 wxglade 并在之后手动自定义。
这样做花了 15 分钟,包括错误(我没有填写列表控件,抱歉):
这是我遵循的过程:
1) Add a Frame widget, select a wx.Frame.
2) Customize wx.Frame properties:
Give the Frame a MenuBar (the property dialog for the menubar appears).
Customize MenuBar: Add File, Edit...
Go back to the Frame properties' View (click the Frame icon on the wxglade Tree View).
(not nice but it's the way I found to go in and out from Menu and StatusBar dialogs).
Give the wx.Frame a StatusBar. Go back (click the Frame icon in the wxglade Tree View).
3) Create 3 vertical slots from the default BoxSizer (right-click on the sizer + add * 3)
1st slot:
Add a BoxSizer with 5 horizontal slots
Set proportion=0 to the sizer, set border=5 and mark wxALL
Add 4 Buttons and a Spacer in those slots
Mark EXPAND and set proportion=1 in the Spacer properties.
2nd slot:
Add a SplitterWindow. Select Vertical type.
Optionally set border=5 with wxALL
Add a BoxSizer to each section of the SplitterWindow
At its left, add a ListCtrl
At its right, add a NoteBook
Customize NoteBook:
Add 4 sheets.
Add BoxSizer with 2 vertical slots to first notebook sheet.
1st slot: insert a wx.Panel.
2nd slot: add a BoxSizer with 3 horizontal slots.
Set proportion=0 to the sizer.
Add 2 buttons and 1 Spacer in those slots.
Mark EXPAND and set proportion=1 in the Spacer properties.
3rd slot:
Add a BoxSizer with 5 horizontal slots.
Set proportion=0 to the sizer, set border=5 with wxALL
Add 2 Buttons, 1 Spacer and 2 Buttons more.
Mark EXPAND and set proportion=1 in the Spacer properties.
4) Give background colour to the Frame.
(Choose wisely, you still have 5 minutes left of the 15 allotted).
最后,自定义标签、sizer 和小部件名称等。
保存 wxGlade 文件以备将来更改并生成 Python 文件(在顶部的“应用程序”对话框中)。
技巧: 不要修改生成的文件,而是在另一个文件中导入和子类化您的 Frame 以对其功能进行编码。
最后一个注意事项: 根据我的经验,Linux 和 Windows 存在一些差异,其大小和背景有所不同。在 Linux 中,不要使用第 3 步中指示的默认 Frame 的 BoxSizer。而是在其上添加一个 wx.Panel,向面板添加一个 BoxSizer 并继续从这个 sizer 构建。
关于python - 从 wxPython 开始,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8877095/