对如何构建 GUI (wxpython) 感到困惑
我从一本书转到另一本书,从谷歌搜索到另一本书,我注意到每一本书都以完全不同的方式启动主窗口。
我不想养成坏习惯,所以有人可以给我最好的这些选择以及为什么这是更好的方法。以下是我见过的所有方法
A)
类 iFrame(wx.Frame): def init(....): wx.Frame._init_(...)
B)
类 iFrame(wx.Frame): def init(...): super_init_(...)
C)
然后我看到一些使用面板来代替,例如
类 iPanel(wx.Panel) def init(...): wx.Panel.init(...)
D)
更令人困惑的是,有些人正在使用 wx 的常规 App 类
iApp类(wx.App): def OnInit(self): wx.Frame.init(...)
如果我的某些结构是错误的,请原谅我,但我突然想起这些,再次提问...其中哪一个,如果ANY 是构建 GUI 的最佳方式。当教程和书籍都以不同的方式编辑时,很难遵循它们
:抱歉,如果格式不正确,但通常它可以工作......
I've gone from one book to another, one google search to another and I notice EVERY SINGLE ONE starts the main window in a completely different way.
I don't want to pick up bad habits so can someone please give me the best of these options and why its the better method. Below are all the ways i've seen it done
A)
class iFrame(wx.Frame):
def init(....):
wx.Frame._init_(...)
B)
class iFrame(wx.Frame):
def init(...):
super_init_(...)
C)
Then I see some that uses the Panel instead such as
class iPanel(wx.Panel)
def init(...):
wx.Panel.init(...)
D)
And even more confusing some are using the regular App class of wx
class iApp(wx.App):
def OnInit(self):
wx.Frame.init(...)
Forgive me if some of my structures are wrong but I'm recalling these off the top of my head, Question again...Which one of these, IF ANY is the best way to structure the GUI. It's hard following tutorials and books when they all do things in diff ways
edit: Sorry if format is not correct, but normally it works...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我最喜欢的开始 wx 应用程序开发的方法是:
另请参阅这个 问题,这是相关的。
My favorite way to start wx application development is:
See also this question, which is related.
别担心。现在做出错误的选择不会毁掉你未来的编程。
您提到的选项都没有错误。它们的做法都不同,因为不同的应用程序有不同的要求。没有一种方法是最好的。
只要做你想做的事,做对你有用的事,一旦你更加熟悉,你就会明白为什么不同的代码会有不同的做法。
Don't worry about it. You aren't going to ruin your future programming by making the wrong choice now.
None of the options you mention are wrong. They all do things differently because different applications have different requirements. No one way is best.
Just work on what you want and do what works for you, and once you have greater familiarity then you'll understand why different code does it differently.
我经历了惨痛的教训才知道,正如在每个应用程序中一样,封装很重要。 wxPython 特有的一点是,主框架对象应该只有一个面板小部件,以及可选的菜单栏、工具栏和状态栏小部件。没有别的了。
这是我的新 wxPython 应用程序的基本模式:
(2019 年 2 月 7 日更新:Wx Phoenix 和 Python 3)
I have learned the hard way that, as in every application, encapsulation is important. And peculiar to wxPython, the main frame object should have precisely one panel widget, plus optional menu bar, toolbar and status bar widgets. Nothing else.
This is my basic pattern for new wxPython applications:
(Updated 2019 Feb 07: Wx Phoenix and Python 3)
为了回应 XilyummY 的评论,我添加了这个附加答案,以展示如何在单独的文件中组织主要类。
这是我基于四个文件的解决方案:
代码按以下顺序排列:
main.py
main_panel.py
menu_bar.py
tool_bar.py
In response to a comment by XilyummY, I have added this additional answer to show how the main classes can be organised in separate files.
This is my solution based on four files:
The code follows in this order:
main.py
main_panel.py
menu_bar.py
tool_bar.py