Using TK and the canvas.

K

Kalibr

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 :)
 
R

r

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 :)

You should really check out wxPython, there is support for just this
type of thing. of course you could do this with Tkinter, but just
thinking about it makes my head hurt :).
 
K

Kalibr

[snip]

You should really check out wxPython, there is support for just this
type of thing. of course you could do this with Tkinter, but just
thinking about it makes my head hurt :).

Alright, I shall investigate. Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top