werte aus dict lesen
Verfasst: Mittwoch 30. August 2006, 21:00
Hallo,
wie würdet ihr das folgende Problem lösen.
es muss doch irgendwie auch einfacher gehen ?
schonmal danke.
Gruss
pyStyler
wie würdet ihr das folgende Problem lösen.
Code: Alles auswählen
from Tkinter import *
class Demo:
def __init__(self, fenster):
self.root=fenster
self.wdict= {'aname':10,
'cname':30,
'bname':20,
'dname':40,
}
for xv in range(len(self.wdict)):
setattr(self, 'of%s' %xv, Frame(self.root) )
for name in self.wdict.keys():
button=Button(getattr(self, 'of%s' %xv),
text=name,width=14, height=4,
command=lambda s=self,
wert=name :s.ausgabe(wert ))
button.pack(side=LEFT, padx=2, pady=2, expand=YES, fill=BOTH)
getattr(self, 'of%s' %xv).pack(expand=YES, fill=BOTH)
def ausgabe(self, x):
a=self.wdict.get(x)
print a
if __name__=='__main__':
root=Tk()
Demo(root)
root.mainloop()
schonmal danke.
Gruss
pyStyler