我正在尝试将代码从 main.py 移动到一个名为 GameWindowManager.py 的可调用类/模块中,
我对此很陌生,我完全迷路了。
它在 main 中工作,我可以调用 Buttons 类,但是当我尝试制作模块 GameWindowManager 时,我得到一个 tlc 不是属性错误。
请帮助,如果可能的话,简单地解释一下。谢谢你。
主文件
'''
main.py
Created on Oct 2, 2013
@author: noel
ChronoProjo Vesion 3.0
'''
from tkinter import *
from chrono.button import *
from chrono.GameWindowManager import *
class ChronoProjo(Frame):
"""self is the main programe"""
def __init__(self,master=None):
"""Initialize your self"""
"""Display the curent Operating System"""
print (sys.platform)
"""Initialise the base class"""
Frame.__init__(self)
ButtonManager.makeButton ( self, "new" )
ButtonManager.makeButton ( self, "load" )
ButtonManager.makeButton ( self, "quit" )
ButtonManager.makeButton ( self, "save as" )
"""Set the Window Title and Icon"""
self.master.title ( "Chrono Generic Toolbar" )
if sys.platform == 'win32':
#make an icon here
pass
self.pack ( side=TOP, fill=X )
root = Tk()
#create a toolbar
if __name__ == "__main__":
ChronoProjo().mainloop()
按钮.py
'''
button.py
Created on Oct 4, 2013
@author: noel
button Vesion 1.0
'''
from tkinter import *
#from tkinter.messagebox import *
class ButtonManager():
def makeButton(self, name):
if name == "new":
menuButton = Button ( self, text = name, width = 11, command = ButtonManager.newGameCallback )
elif name == "load":
menuButton = Button(self, text = name, width = 11, command = ButtonManager.loadCallback)
elif name == "quit":
menuButton = Button(self, text = name, width = 11, command = ButtonManager.quitCallback)
elif name == "save as":
menuButton = Button(self, text = name, width = 11, command = ButtonManager.saveAsCallback)
menuButton.pack(side=LEFT, padx=2, pady=2)
def newGameCallback(self):
print ("called the new callback!")
def loadCallback(self):
print ("called the load callback!")
def quitCallback(self):
print ("called the quit callback!")
def saveAsCallback(self):
print ("called the save as callback!")
游戏窗口管理器.py
'''
GameWindowManager.py
Created on Oct 14, 2013
@author: noel
'''
from tkinter import *
from chrono.button import *
class GameWindowManager(object):
'''
This is to manage the various game windows that will be used throughout the game
'''
def __init__(self,frame):
"""Initialize your self"""
"""Display the curent Operating System"""
print (sys.platform)
"""Initialise the base class"""
Frame.__init__(self)
ButtonManager.makeButton ( self, "new" )
ButtonManager.makeButton ( self, "load" )
ButtonManager.makeButton ( self, "quit" )
ButtonManager.makeButton ( self, "save as" )
"""Set the Window Title and Icon"""
self.master.title ( "Chrono Generic Toolbar" )
if sys.platform == 'win32':
self.master.wm_iconbitmap ( './assets/img/NLFFace.ico' ) #haven't worked out how to do self in Linux yet
pass
self.pack ( side=TOP, fill=X )