dazu wollte ich eine liste mit alles shemata erstellen und über die dann die menüeinträge
mein Code:
Code: Alles auswählen
from Tkinter import *
class Farbshema:
def __init__(self):
self.shema1={'background':'#006610', 'foreground':'#FFFF00','crbuttonbg2':'#8a4400', 'name':'Jungle'}
self.shema2={'background':'#F8F8F8', 'foreground':'#2000CC','crbuttonbg2':'#DDDDDD', 'name':'Ice'}
self.shema3={'background':'#000010', 'foreground':'#FFFFA0','crbuttonbg2':'#000050', 'name':'Stars'}
self.shema4={'background':'#00C8FF', 'foreground':'#FFFFA0','crbuttonbg2':'#000050', 'name':'Stars'}
self.shema5={'name':'Windows', 'foreground':'#000000'}
self.shemata=[self.shema1,self.shema2,self.shema3,self.shema4, self.shema5]
self.active=self.shema5
def change(self, master, s, sg1=None, sg2=None, par=None, menu=None):
self.activ=s
if not s['name']=='Windows':
master.tk_setPalette(background=s['background'], foreground=s['foreground'],
activeForeground=s['foreground'],activeBackground=s['background'],
selectColor=s['crbuttonbg2'],selectBackground=s['foreground'],
selectForeground=s['background'],insertBackground=s['crbuttonbg2'],
highlightBackground=s['background'],disabledForeground=s['foreground'],
highlictColor=s['foreground'])
master['bg']=s['crbuttonbg2']
for x in sg1.f:
x.config(selectcolor=s['background'])
for x in sg2.f:
x.config(selectcolor=s['background'])
menu.farbmenu.config(bg='#C0C0B4', fg='#000000')
par.tisch.config(bg=s['crbuttonbg2'])
par.tisch.itemconfig('all', fill=s['foreground'])
#Menu:
class Menuleiste:
def __init__(self, master, col, sg1=None, sg2=None, par=None):
self.leiste=Menu(master, font=myfont)
master.config(menu=self.leiste)
self.farbmenu=Menu(self.leiste, font=myfont)
self.leiste.add_cascade(label='Farb-Optionen', menu=self.farbmenu)
a=[]
for x in col.shemata:
def y():
col.change(root, x, sg1=sg1, sg2=sg2, par=par, menu=self)
a=a+[x,y]
for z in a:
self.farbmenu.add_command(label=z[0]['name'], command=z[1], font=myfont)
col.change(root, col.active, sg1=sg1, sg2=sg2, par=par, menu=self)
colors=Farbshema()
root=Tk()
#...anderen Klassen...
menuleiste=Menuleiste(root, colors, sg1=stargate1, sg2=stargatea, par=parabelrechner)
line 52, in __init__
self.farbmenu.add_command(label=z[0]['name'], command=z[1], font=myfont)
KeyError: 0
meine Frage:
leigt es an dem def in der forschleife???