在 Tkinter Gui 中创建框架类
我正在开发一个 Gui,我想知道如何创建一个实现框架的类。
例如
class WindowContent(Tkinter.?)
""" This class would create a frame for my program window """
class App(Tkinter.Tk):
""" main window constructor """
def __init__(self):
Tkinter.Tk.__init__(self)
program_window = WindowContent ?
self.config(window = window_content) ?
rgds,
I'm working on a Gui and I'd like to know how to create a class that would implement frame.
e.g.
class WindowContent(Tkinter.?)
""" This class would create a frame for my program window """
class App(Tkinter.Tk):
""" main window constructor """
def __init__(self):
Tkinter.Tk.__init__(self)
program_window = WindowContent ?
self.config(window = window_content) ?
rgds,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了答案:
I found the answer :
为什么需要一个创建多个框架的类?创建一个创建多个框架的类并不是一个很好的解决方案。你不需要为此单独上一堂课。
为每个框架创建单独的类,或者仅在应用程序中创建方法来创建每个框架。我更喜欢后者,但如果您想要一个可以在多个上下文中使用的框架,有时创建一个类是有意义的。
当我制作 GUI 时,我的代码结构如下:
通过这种方式,每个主要部分都有自己的方法来隐藏小部件创建的详细信息。当然,您可以让每个框架都是一个自定义对象,但通常这是不必要的。
Why do you want a class that creates several frames? Creating one class that creates multiple frames is not a very good solution. You don't need a single class for that.
Either create separate classes for each frame, or just create methods in your app to create each frame. I prefer the latter, but if you want a frame that can be used in multiple contexts it sometimes makes sense to create a class.
When I do a GUI I structure my code like this:
In this way, each major section gets its own method to hide the details of widget creation. You could, of course, have each frame be a custom object but usually that's unnecessary.