Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Using TK and the canvas.

Reply
Thread Tools

Using TK and the canvas.

 
 
Kalibr
Guest
Posts: n/a
 
      02-10-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
hereapologies 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
 
Reply With Quote
 
 
 
 
r
Guest
Posts: n/a
 
      02-10-2009
On Feb 10, 1:27*pm, Kalibr <(E-Mail Removed)> 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 .
 
Reply With Quote
 
 
 
 
Kalibr
Guest
Posts: n/a
 
      02-10-2009
On Feb 11, 5:51*am, r <(E-Mail Removed)> wrote:
> On Feb 10, 1:27*pm, Kalibr <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best practices for using forms authentication and security in a hosted env (was: Re: Using a Forms authentication in a shared hosting environment) JEFF ASP .Net 1 11-12-2007 07:00 PM
build a hierarchical tree, without using DOM,schema, and sax using expat parser and c pharioum@gmail.com XML 2 11-05-2007 02:24 PM
Using DataAdapter and using an output parameter robin9876@hotmail.com ASP .Net 0 05-25-2006 03:40 PM
Class B using Class C, and Class A using both B and C jd C++ 3 11-27-2004 12:13 AM
using pthread to receive data on a socket and simultaneously play it using /dev/dsp kanchan C Programming 1 11-13-2004 10:33 PM



Advertisments