下午好,StackOverflow社区,
我是第一个寻求建议的GUI编码人员.我正忙于物理化学理学硕士课程.
我有一个简单的问题:
将我的整个代码包装到一个类中被认为是不好的做法吗?
我试图在类中拆分我的代码,但在处理多个类时,我似乎无法正确获得初始化魔术方法.作为参考,我附上了自己的init.也许你可以帮助我理解我怎么可能把所有这些分成不同的类,这可以分成不同的模块.
谢谢!
class ApplicationUI(tk.Tk):
def __init__(self):
"""
Initialises the GUI and parent.
"""
tk.Tk.__init__(self)
self.create_canvas()
self.create_menus()
self.create_main_buttons()
self.data = {}
self.call_counter = 0
self.file_opts = {}
self.file_opts['filetypes'] = [('Text Files', '.txt'),('CSV Files', '.csv'),('All Files', '.*')]
self.file_opts['initialdir'] = 'C:\\Users\xxx\Documents'
self.file_opts['title'] = 'File'
app = ApplicationUI()
app.mainloop()
最佳答案
As mentioned in the comments this is a subjective matter or question
of trading-off pros and cons.
无论如何有一个很好的pdf on clean code讨论了一些方法和经验法则.关于课程还有整整一章(10).所以也许这是一个开始感觉的好地方.