Code: Alles auswählen
raceback (most recent call last):
File "tk-import-gui_oo.py", line 8, in ?
class tk_gui:
File "tk-import-gui_oo.py", line 27, in tk_gui
for zeile, lst in enumerate(konto.get_konto_liste() ):
NameError: name 'konto' is not defined
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import konto_core_004
import Tix
class tk_gui:
def __init__(self):
konto = konto_core_004.Konto()
def lade():
konto.add_to_konto_liste(k.konto_liste, k.import_csv("test.csv"))
def loesche():
konto.loesche_konto()
def ok_command():
print "ok"
root = Tix.Tk()
win = Tix.ScrolledWindow(root, scrollbar='auto',height=500)
win.pack(fill=Tix.X, expand=1)
for zeile, lst in enumerate(konto.get_konto_liste() ):
zeile2 = zeile +1
# Farbe wegen negativer Zahl
if lst[9] < 0:
fg_color = "red"
else: fg_color = None #"blue"
# Hintergrund jeder 2. Zeile weiss
if zeile % 2: bg_color = "white"
else: bg_color = None
for spalte, element in enumerate(lst[:7]):
Tix.Label(win.window, text=element, bd=1, relief="ridge",
anchor=Tix.N+Tix.W,justify=Tix.LEFT, fg=fg_color, background=bg_color
).grid(row=zeile2, column=spalte, sticky=Tix.E+Tix.W+Tix.N+Tix.S)
box = Tix.ButtonBox(root, orientation=Tix.HORIZONTAL, bg="blue", padx=0, pady=0,height=200)
box.add('import', text='Importiere Kontoauszug', underline=0,
command=lambda root=root: lade(), bg="green")
box.add('del', text='loesche Konto', underline=0,
command=lambda root=root: ok_command(), relief="flat", bg="red")
box.add('cancel', text='Programm beenden', underline=0,
command=lambda root=root: ok_command())
box.pack(side=Tix.BOTTOM, fill=Tix.X)
root.mainloop()
if __name__ == '__main__':
gui = tk_gui()
Jetzt möchte ich auch gerne meine kleine GUI als Klasse schreiben, steige aber erst gerade in das Thema ein und weiß nicht was ich falsch mache.
cu Sebastian