Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tkinter is getting the best of me

Status
Not open for further replies.

brotherjustice

Programmer
Jun 19, 2003
5
CA
I'll paste here all my code near the end in the displayclic and displayclicbox objects i've fudged up in terms of master slave relationships ala tk. I only a few hairs left so rather than pull them out i thought maybe someone could give me a hand. It would be greatly appreciated.

# this object is the foundation of the program it holds all the values required for and place
#on the dial at each clic. That is speed, attack, defense and damage will each be a clic box
# each containing a value, a color, a superpower and a position in a particular clic on which
#4 clicboxes are contained
Code:
class clicbox:


    def __init__(self,value=0,color="white",superpower="none",pos=0):
        self.value=value
        self.color=color
        self.superpower=superpower
        self.pos=pos
    def add(self,value,color,superpower,pos):
        self.value=value
        self.color=color
        self.superpower=superpower
        self.pos=pos

#it is a containerclass designed to keep track of all the clicboxes for a given clic on a dial
class clic:
    
    def __init__(self,value1,color1,superpower1,pos1,value2,color2,superpower2,pos2,value3,color3,superpower3,pos3,value4,color4,superpower4,pos4):
#                 ,list=[],y=clicbox()):
        list=[]#this list is to be populated with clic objects later proper information hiding will be used
        y=clicbox()#fuck off peter this a temporay clicbox name y
    
        self.list = list
        self.y = y
        
        self.value1=value1
        self.color1=color1
        self.superpower1=superpower1
        self.pos1=pos1

        self.value2=value2
        self.color2=color2
        self.superpower2=superpower2
        self.pos2=pos2

        self.value3=value3
        self.color3=color3
        self.superpower3=superpower3
        self.pos3=pos3

        self.value4=value4
        self.color4=color4
        self.superpower4=superpower4
        self.pos4=pos4

        #this section adds 4 clic boxes to the clic.list(remember each position contains a clic box)
             #speed
        y.add(value=self.value1, color=self.color1, superpower=self.superpower1, pos=self.pos1)
        list.append(copy.deepcopy(y))
             #attack
        y.add(value=self.value2, color=self.color2, superpower=self.superpower2,pos=self.pos2)
        list.append(copy.deepcopy(y))
             #defense
        y.add(value=self.value3, color=self.color3, superpower=self.superpower3, pos=self.pos3)
        list.append(copy.deepcopy(y))
             #damage
        y.add(value=self.value4, color=self.color4, superpower=self.superpower4,pos=self.pos4)
        list.append(copy.deepcopy(y))

        
 #   def mycopy(self,x):
 #       return copy.deepcopy(x)


pass

#the dial class is a blue print for a representation of all the clic values on a particular
#hero. It contains a [] which is used to store the clics a hero contains.

class dial:

    def __init__(self,clic1=clicbox(),clic2=clicbox(),clic3=clicbox(),clic4=clicbox(),clic5=clicbox(),clic6=clicbox(),clic7=clicbox(),clic8=clicbox(),clic9=clicbox(),clic10=clicbox(),clic11=clicbox(),clic12=clicbox()):
        thedial=[]
        self.thedial=thedial
        thedial.append(clic1)
        thedial.append(clic2)
        thedial.append(clic3)
        thedial.append(clic4)                       
        thedial.append(clic2)
        thedial.append(clic3)
        thedial.append(clic4)
        thedial.append(clic5)
        thedial.append(clic6)
        thedial.append(clic7)
        thedial.append(clic8)
        thedial.append(clic9)
        thedial.append(clic10)
        thedial.append(clic11)
        thedial.append(clic12)
    
pass
#the class hero is a blueprint contain all that is need to make a hero
#it contains a dial for that hero as well as other values such as name rank and point value
class hero:

    def __init__(self,range,numberofattacks,name,team,level,set,points,collect,thisdial=dial()):
        self.points=points
        self.collect=collect
        self.thisdial=thisdial
        self.range=range
        self.numberofattacks=numberofattacks
        self.name=name
        self.team=team
        self.level=level
        self.set=set
        self.herodial=thisdial.thedial

    
import copy




def printclic(x):#this function is just for test purposes 

    print "SPEED:"       
    print
    print x.list[0].value
    print x.list[0].color
    print x.list[0].superpower
    #print x.list[0].pos
    print
    print "ATTACK"
    print x.list[1].value
    print x.list[1].color
    print x.list[1].superpower
    #print x.list[1].pos
    print
    print "DEFENSE"
    print
    print x.list[2].value
    print x.list[2].color
    print x.list[2].superpower
    #print x.list[2].pos
    print
    print "DAMAGE"
    print
    print x.list[3].value
    print x.list[3].color
    print x.list[3].superpower
    #print x.list[3].pos

#clics for skrull warrior rookie
crap1 = clic(6,"white","none",1,7,"white","none",1,15,"white","none",1,1,"white","none",1)
crap2 = clic(5,"white","none",2,5,"white","none",2,13,"white","none",2,1,"white","none",2)
crap3 = clic(5,"white","none",3,5,"white","none",3,12,"white","none",3,1,"white","none",3)
crap4 = clic(5,"white","none",4,4,"white","none",4,12,"white","none",4,1,"white","none",4)
testdial=dial(crap1,crap2,crap3,crap4)
skrullwarrior1=hero(8,1,"Skrull Warrior","Skrulls",1,"infinity challange",14,"022" ,testdial)

#clics for skrull warrior experienced
crap5 = clic(7,"white","none",1,7,"white","none",1,15,"white","none",1,2,"white","none",1)
crap6 = clic(6,"white","none",2,6,"white","none",2,13,"white","none",2,1,"white","none",2)
crap7 = clic(5,"white","none",3,5,"white","none",3,13,"white","none",3,1,"white","none",3)
crap8 = clic(5,"white","none",4,4,"white","none",4,12,"white","none",4,1,"white","none",4)
testdial=dial(crap5,crap6,crap7,crap8)
skrullwarrior2=hero(8,1,"Skrull Warrior","Skrulls",2,"infinity challange",16,"023" ,testdial)


#print skrullwarrior1.collect
#print skrullwarrior2.collect
#clics for skrull warrior experienced
#printclic(skrullwarrior1.thisdial.thedial[0])
#printclic(skrullwarrior1.thisdial.thedial[1])
#print (testdial.thedial[0][0]).value




from Tkinter import *							 
                                                                         
class Application(Frame):						 


    def __init__(self,heman=hero(0,1,"noname","none",1,"hypertime",23,00), master=None):					
                Frame.__init__(self, master)
                self.herox=heman
                self.pack()					
                self.create()#Widgets()

                                                                        
    def create(self):
    

        #herox = self.heman    
        name1 = Label(self, text =self.herox.name)
        name1.grid(row=0, column=4, columnspan=4)
        if self.herox.level==1:
            xplevel=Label(self,text="rookie",bg="yellow")
        elif self.herox.level==2:
            xplevel=Label(self,text="experienced",bg="blue")
        elif self.herox.level==3:
            xplevel=Label(self,text="veteran",bg="red")
        xplevel.grid(row=0,column=10,columnspan=4)
        Label(self,text="ATTACKS: "+str(self.herox.numberofattacks)).grid(row=8,column=6,columnspan=4)
                                                                    
                                                                    
        upper= Label(self, text="Click Number")
        upper1= Label(self, text="  1 ")
        upper2= Label(self, text="  2 ")
        upper3= Label(self, text="  3 ")
        upper4= Label(self, text="  4 ")
        upper5= Label(self, text="  5 ")
        upper6= Label(self, text="  6 ")
        upper7= Label(self, text="  7 ")
        upper8= Label(self, text="  8 ")
        upper9= Label(self, text="  9 ")
        upper10= Label(self, text=" 10 ")
        upper11= Label(self, text=" 11 ")
        upper12= Label(self, text=" 12 ")

        upper.grid(row=2, column=0)
        upper1.grid(row=2, column=1)
        upper2.grid(row=2, column=2)
        upper3.grid(row=2, column=3)
        upper4.grid(row=2, column=4)
        upper5.grid(row=2, column=5)
        upper6.grid(row=2, column=6)
        upper7.grid(row=2, column=7)
        upper8.grid(row=2, column=8)
        upper9.grid(row=2, column=9)
        upper10.grid(row=2, column=10)
        upper11.grid(row=2, column=11)
        upper12.grid(row=2, column=12)
      

        speedq= Label(self, text="SPEED")
        attackq= Label(self, text="ATTACK")
        defenseq= Label(self, text="DEFENSE")
        damageq= Label(self, text="DAMAGE") 
        speedq.grid(row=3, column=0)
        attackq.grid(row=4)
        defenseq.grid(row=5)
        damageq.grid(row=6)
        Label(self,text="TEAM: " + self.herox.team).grid(row=7,column=0,columnspan=2)
        Label(self,text="POINTS: " + str(self.herox.points),fg="red").grid(row=7,column=1,columnspan=6)
        Label(self,text="NUMBER: " + str(self.herox.collect)).grid(row=7,column=5,columnspan=6)
        Label(self,text="SET: " + self.herox.set).grid(row=8,column=0,columnspan=4)
        Label(self,text="RANGE: " + str(self.herox.range)).grid(row=0,column=0,columnspan=2)
        x=0
        

#        print len(herox.thisdial.thedial)
        while x<(len(self.herox.thisdial.thedial[x].list)):
        
            Label(self,text=(self.herox.herodial[x].list[0]).value ,bg=(self.herox.herodial[x].list[0]).color).grid(row=3, column=x+1)
            Label(self,text=(self.herox.herodial[x].list[1]).value ,bg=(self.herox.herodial[x].list[1]).color).grid(row=4, column=x+1)                
            Label(self,text=(self.herox.herodial[x].list[2]).value ,bg=(self.herox.herodial[x].list[2]).color).grid(row=5, column=x+1)
            Label(self,text=(self.herox.herodial[x].list[3]).value ,bg=(self.herox.herodial[x].list[3]).color).grid(row=6, column=x+1)		
       
            if self.herox.herodial[x].list[3].color == &quot;black&quot;:
                Label(self, text=(self.herox.herodial[x].list[3]).value, bg=(self.herox.herodial[x].list[3]).color, fg=&quot;white&quot;).grid(row=6, column=x+1)		
            if self.herox.herodial[x].list[2].color == &quot;black&quot;:
                Label(self, text=(self.herox.herodial[x].list[2]).value, bg=(self.herox.herodial[x].list[2]).color, fg=&quot;white&quot;).grid(row=5, column=x+1)		
            if self.herox.herodial[x].list[1].color == &quot;black&quot;:
                Label(self, text=(self.herox.herodial[x].list[1]).value, bg=(self.herox.herodial[x].list[1]).color, fg=&quot;white&quot;).grid(row=4, column=x+1)		
            if self.herox.herodial[x].list[0].color == &quot;black&quot;:
                Label(self, text=(self.herox.herodial[x].list[0]).value, bg=(self.herox.herodial[x].list[0]).color, fg=&quot;white&quot;).grid(row=3, column=x+1)		

            x=x+1
        z=len(self.herox.herodial[x].list)
        while z <12:
            Label(self,text=&quot;KO&quot; ,bg=&quot;white&quot;,fg=&quot;red&quot;).grid(row=3, column=z+1)
            Label(self,text=&quot;KO&quot; ,bg=&quot;white&quot;,fg=&quot;red&quot;).grid(row=4, column=z+1)
            Label(self,text=&quot;KO&quot; ,bg=&quot;white&quot;,fg=&quot;red&quot;).grid(row=5, column=z+1)
            Label(self,text=&quot;KO&quot; ,bg=&quot;white&quot;,fg=&quot;red&quot;).grid(row=6, column=z+1)
            z = z + 1
        
                                                                        
#app = Application(skrullwarrior2)
#app1 =Application(skrullwarrior1)
#app1.mainloop()
#app.mainloop()
#mydisplay()
#print skrullwarrior1.herodial[0].list[0].value







class displayclicbox:

    def __init__(self,temptk,boxname,col,rowd):
        self.temptk=temptk
        Label(self,self.temptk,text=boxname,font = (&quot;arial&quot;, 16)).grid(row=0,column=col,columnspan=2)

        self.valuebox=Listbox(clicwindow,height=20,width=2,selectmode=SINGLE,exportselection=0)
        self.valuebox.grid(column=col,row=rowd)
        self.valuechoices=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
        for item in self.valuechoices:
            self.valuebox.insert(END,item)
            
        self.colorbox=Listbox(HeroEntry,height=12,width=10,selectmode=SINGLE,exportselection=0)
        self.colorbox.grid(column=col+1,row=rowd)
        self.colorchoices=[&quot;PURPLE&quot;,&quot;BROWN&quot;,&quot;DARK BLUE&quot;,&quot;GREEN&quot;,&quot;BLUE&quot;,&quot;ORANGE&quot;,&quot;YELLOW&quot;,&quot;RED&quot;,&quot;GREY&quot;,&quot;BLACK&quot;,&quot;WHITE&quot;]
        for item in self.colorchoices:
            self.colorbox.insert(END,item)
       
        
    def getvalue(self):
        return self.valuebox.get(self.valuebox.curselection())


    def getcolor(self):
        
        return self.colorbox.get(self.colorbox.curselection())
    
class displayclic:
    
    def __init__(self,windowq):
        self.currentpos=0
        self.HeroEntry=windowq
        self.HeroEntry.title(&quot;Hero Enty Form&quot;)
        self.speed=displayclicbox(self.HeroEntry,&quot;SPEED&quot;,1,2)
        self.attack=displayclicbox(self.HeroEntry,&quot;ATTACK&quot;,5,2)
        self.defense=displayclicbox(self.HeroEntry,&quot;DEFENSE&quot;,9,2)
        self.damage=displayclicbox(self.HeroEntry,&quot;DAMAGE&quot;,13,2)
        self.tempcliclist=[]
        self.btn = Button(self.HeroEntry, text = &quot;NEXT CLICK&quot;, command=addclicp)
        self.btn.grid(row=3,column=1,columnspan=3)
        self.btn = Button(self.HeroEntry, text=&quot;END&quot;,command=&quot;end clic entry&quot;)
        self.passthis=self.Heroentry
    def getwindowcrap():
        return self.passthis

    def addclicp():
        speedval=self.speed.getvalue
        speedcol=self.speed.getcolor
        attackval=self.attack.getvalue
        attackcol=self.attack.getcolor
        defenseval=self.defense.getvalue
        defensecol=self.defense.getcolor
        damageval=self.damage.getvalue
        damagecol=sel.fdamage.getcolor
        tempclic=clic(speedval,speedcol,getpower(&quot;SPEED&quot;,speedcol),self.currentpos,attackval,attackcol,getpower(&quot;ATTACK&quot;,attackcol),self.currentpos,defenseval,defensecol,getpower(&quot;DEFENSE&quot;,defensecol),self.currentpos,damageval,damagecol,getpower(&quot;DAMAGE&quot;,damagecol),self.currentpos)
        self.tempcliclist[self.currentpos]=copy.deepcopy(tempclic)

        self.currentpos=self.currentpos + 1
        
                  

###/could be module made just for assigning powers based on color and type
def getpower(powertype,color):
    
    if powertype==&quot;SPEED&quot;:
        power=getspeed(color)
    elif powertype==&quot;ATTACK&quot;:
        power=getattack(color)
    elif powertype==&quot;DEFENSE&quot;:
        power=getdefense(color)
    elif powertype==&quot;DAMAGE&quot;:
        power=getdamage(color)

    return power

    
def getspeed(color=&quot;none&quot;):
    speedpowers=[&quot;NONE&quot;,&quot;CHARGE&quot;,&quot;FLURRY&quot;,&quot;MINDCONTROL&quot;,&quot;LEAP/CLIMB&quot;,&quot;PHASING&quot;,&quot;STEALTH&quot;,&quot;RUNNING SHOT&quot;,&quot;FORCE BLAST&quot;,&quot;HYPERSONIC SPEED&quot;,&quot;PLASTICITY&quot;]
    speedcolors=[&quot;WHITE&quot;,&quot;GREEN&quot;,&quot;RED&quot;,&quot;BLUE&quot;,&quot;ORANGE&quot;,&quot;YELLOW&quot;,&quot;BLACK&quot;,&quot;GRAY&quot;,&quot;PURPLE&quot;,&quot;BROWN&quot;,&quot;DARK BLUE&quot;]

    i=0
    while i<=9:
        if color == speedcolors [i]:
            return speedpowers [i]
        else:
            i = i + 1

def getattack(color=&quot;none&quot;):
    attackpowers=[&quot;NONE&quot;,&quot;SUPER STRENGTH&quot;,&quot;BLADES/CLAWS/FANGS&quot;,&quot;INCAPACITATE&quot;,&quot;ENERGY EXPLOSION&quot;,&quot;PULSE WAVE&quot;,&quot;STEAL ENERGY&quot;,&quot;TELEKINESIS&quot;,&quot;SMOKE CLOUD&quot;,&quot;POISON&quot;,&quot;PSYCHIC BLAST&quot;,&quot;SUPER STRENGTH&quot;]
    attackcolors=[&quot;WHITE&quot;,&quot;GREEN&quot;,&quot;RED&quot;,&quot;BLUE&quot;,&quot;ORANGE&quot;,&quot;YELLOW&quot;,&quot;BLACK&quot;,&quot;GRAY&quot;,&quot;PURPLE&quot;,&quot;BROWN&quot;,&quot;DARK BLUE&quot;,&quot;GREEN&quot;]

    i=0
    while i<=10:
        if color==attackcolors [i]:
            return attackpowers [i]
        else:
            i = i + 1
####HERE
def getdefense(color=&quot;none&quot;):
    defensepowers=[&quot;NONE&quot;,&quot;ENERGY SHEILD/DEFLECTION&quot;,&quot;SUPER SENSES&quot;,&quot;BARRIER&quot;,&quot;TOUGHNESS&quot;,&quot;DEFEND&quot;,&quot;REGENERATION&quot;,&quot;INVULNERABILITY&quot;,&quot;WILLPOWER&quot;,&quot;IMPERVIOUS&quot;,&quot;MASTERMIND&quot;]
    defensecolors=[&quot;WHITE&quot;,&quot;GREEN&quot;,&quot;RED&quot;,&quot;BLUE&quot;,&quot;ORANGE&quot;,&quot;YELLOW&quot;,&quot;BLACK&quot;,&quot;GRAY&quot;,&quot;PURPLE&quot;,&quot;BROWN&quot;,&quot;DARK BLUE&quot;]

    i=0
    while i<=9:
        if color==defensecolors [i]:
            return defensepowers [i]
        else:
            i = i + 1

def getdamage(color=&quot;none&quot;):
    damagepowers=[&quot;NONE&quot;,&quot;ENHANCEMENT&quot;,&quot;RANGED COMBAT EXPERT&quot;,&quot;PROBABILITY CONTROL&quot;,&quot;BATTLE FURY&quot;,&quot;SUPPORT&quot;,&quot;OUTWIT&quot;,&quot;LEADERSHIP&quot;,&quot;CLOSE COMBAT EXPERT&quot;,&quot;PERPLEX&quot;,&quot;SHAPE CHANGE&quot;]
    damagecolors=[&quot;GREEN&quot;,&quot;RED&quot;,&quot;BLUE&quot;,&quot;ORANGE&quot;,&quot;SUPPORT&quot;,&quot;BLACK&quot;,&quot;GRAY&quot;,&quot;PURPLE&quot;,&quot;BROWN&quot;,&quot;DARK BLUE&quot;]
    i=0
    while i<=9:
        if color==damagecolors [i]:
            return damagepowers [i]
        else:
            i = i + 1
HeroEntry=Tk()
crap=displayclic(HeroEntry)


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top