Using TK and the canvas.

Discussion in 'Python' started by Kalibr, Feb 10, 2009.

  1. Kalibr

    Kalibr Guest

    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 :)
    Kalibr, Feb 10, 2009
    #1
    1. Advertising

  2. Kalibr

    r Guest

    On Feb 10, 1:27 pm, Kalibr <> wrote:
    [snip]
    > 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 :).
    r, Feb 10, 2009
    #2
    1. Advertising

  3. Kalibr

    Kalibr Guest

    On Feb 11, 5:51 am, r <> wrote:
    > On Feb 10, 1:27 pm, Kalibr <> wrote:
    > [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.
    Kalibr, Feb 10, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave Harris
    Replies:
    1
    Views:
    593
    Peter Otten
    May 28, 2004
  2. Askari
    Replies:
    2
    Views:
    707
    Askari
    Aug 30, 2004
  3. PhilC
    Replies:
    2
    Views:
    882
    PhilC
    Oct 25, 2004
  4. Nainto
    Replies:
    1
    Views:
    301
    Nainto
    Feb 23, 2006
  5. Replies:
    10
    Views:
    259
    Rick Johnson
    Mar 15, 2013
Loading...

Share This Page