Using TK and the canvas.
Kalibr
space.captain.face at gmail.com
Tue Feb 10 14:27:36 EST 2009
Hi all. I'm experimenting with making a UI for a little (well, not
quite) script that basically draws up a tech tree to some skills from
my favorite game. What I'm aiming for looks a little like this site
here:(apologies if I'm not supposed to direct link)
http://www.anderkoo.com/uploads/271/605/NewTechTree.jpg.
Anyway, I made a script which reads data from several files and saves
the data into an array of skill objects, here's what it looks like:
#define the class
class skill:
def __init__(self, name, description, a1, a2, rank, prereq):
self.name = name #string (example is "Anchoring")
self.desc = description #string (example is "blah blah blah")
self.a1 = a1 #string with attributes affecting the skill
(Example is "Int")
self.a2 = a2 #string
self.rank = rank #how hard it is to train (example is "5")
(too lazy to convert to int
self.prereq = prereq #any prerequsites (an array of ["skill",
"levelrequired"])
#the trained level already
self.skillowned = "0" #we change this later on when we access
another file :)
Finally, I set up a class which accepts a parent (normally root), and
the skill in question.
here it is:
class SkillInfo:
def __init__(self, parent, skill):
container = Frame(parent)
container.pack()
#we make this the top frame for some reason
labelcontainer = Frame(container, height=50, width=50)
labelcontainer.pack(side=LEFT, fill=BOTH, expand=YES)
desccont = Frame(container, height=50, width=50) #the
description content
desccont.pack(side=LEFT, fill=BOTH, expand=YES)
#make a name label
Label(labelcontainer, text=skill.name, wraplength=100).pack
(side=TOP, anchor=W)
#print the level buttons
for i in range(1, 6):
button = Button(labelcontainer)
button["text"] = "Level", i
if int(skill.skillowned) >= i:
button["background"] = "green"
button["width"] = 10
else:
button["background"] = "red"
button["width"] = 10
button.pack(anchor=W)
Label(desccont, text=("\n"+skill.desc), wraplength=100).pack()
Now I know all I have to do is set the SkillInfos parent to a canvas,
but how would I arrange and draw the lines? Thanks all :)
More information about the Python-list
mailing list