python - 从 wxPython 开始

标签 python wxpython

我在使用 wxPython 中的 sizer 布置我的表单时遇到了一些挑战,如果有人能让我先开始布置我的表单,我将不胜感激,如图所示。

Sample Form

请分享来源。

谢谢

最佳答案

在设计复杂的图形用户界面时,我不会手动使用 sizer。请使用wxglade然后手动自定义。

做这个花了 15 分钟,包括错误(我没有填写列表控件,抱歉):

enter image description here

这是我遵循的过程:

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 和 widget 名称等。
保存 wxGlade 文件以供将来更改并生成 Python 文件(在顶部的应用程序对话框中)。
技巧:不要修改生成的文件,而是导入您的框架并将其子类化到另一个文件中以对其功能进行编码。

最后一点:根据我的经验,Linux 和 Windows 在 sizer 和背景方面存在一些差异。在 Linux 中,不要使用步骤 3 中指示的默认 Frame 的 BoxSizer。而是在其上添加一个 wx.Panel,将一个 BoxSizer 添加到 Panel 并从该 sizer 继续构建。

关于python - 从 wxPython 开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8877095/

相关文章:

python - 打印每个簇的图像

python - 猴子修补运算符重载在 Python2 与 Python3 中的行为不同

python - wxPython 中可点击图像网格的有效方法?

python - 需要一个适合可视化队列模拟的Python包

python - 如何在 wxPython ComboBox 中存储字符串以外的对象?

python - 将 Django 从 SQLite 转换为 PostgreSQL

python - 将列表转换为数据框中的不同列

python - 每次访问 Flask View 的增量计数器

python - wxpython GetStatusText()

python - wxPython 系统托盘图标