I am writing a 'change' dialog for records in a database.
The 'enter data' dialog (terminErfassen) for the same data records works fine.
In order to reuse as much of the existing code I have made a class for Labels and the values.
The Entry and Text Widgets are repeated in each of the programs.
The dialog 'terminAendern' (change due date) starts with a small window asking for the record number. Pressing the 'lookup' (Daten einlesen) button opens the second window which has the same look as the 'enter data' dialog.
Problem: Although the code is identically written, it works for the Entry-Fields in the main frame, and it fails for the Entry fields in the subframes.
However I am not sure the Frames are the culprits - it seems just the single item which is not identical in the structure.
Here is the code. Rows 0 to 5 get filled with data from the database, the Radiobuttons also work, just the Entries in the subframe have this problem. Find below also an image of the screen.
class TerminAendern(te2.DatenFenster):
"Termine k?nnen ge?ndert werden. Erweiterung von terminErfassen"
def __init__(self, el):
"übernimmt das Fenster aus dem Erfassungsdialog"
super().__init__()
self.ROOT.title("Termin ?ndern")
# Datensatz-Nummer
self.num_wrt = el["nummer"]
# die Werte aus der Datenbank in das Fenster setzen
#--------- row 0 -----------
#self.art_wrt = tk.StringVar() # Operation zB backup, apt-update, extrahieren
self.art_wrt.set(el["art"])
self.ART_EING = tk.Entry(self.FRMEINGAB, textvariable=self.art_wrt, bg='white')
self.ART_EING.grid(column=1, row=0)
self.ART_EING.insert(0, el["art"])
#--------- row 1 -----------
#self.gertwrt = tk.StringVar() # Rechnername oder Ger?t (BoschNyon)
self.gertwrt.set(el["geraet"])
self.GERTEING = tk.Entry(self.FRMEINGAB, textvariable=self.gertwrt, bg='white')
self.GERTEING.insert(90, el["geraet"])
self.GERTEING.grid(column=1, row=1)
#--------- row 2 -----------
#self.brchwrt = tk.StringVar() # Partition/Gegenstand/Aktion/'': TB2, Karten, apt-update
self.brchwrt.set(el["bereich"])
self.BRCHEING = tk.Entry(self.FRMEINGAB, textvariable=self.brchwrt, bg='white')
self.BRCHEING.insert(0, el["bereich"])
self.BRCHEING.grid(column=1, row=2)
#--------- row 3 -----------
#self.bescwrt = tk.StringVar() # Kurztext
self.bescwrt.set(el["kurztext"])
self.BESCEING = tk.Label(self.FRMEINGAB, textvariable=self.bescwrt, bg='lightblue',
text=el["kurztext"],anchor=tk.W, relief=tk.RAISED)
self.BESCEING.grid(column=1, row=3)
#--------- row 4 -----------
#self.haufwrt = tk.IntVar() # H?ufigkeit
self.haufwrt.set(el["haeufigkeit"])
self.HAUFEING = tk.Entry(self.FRMEINGAB, textvariable=self.haufwrt, bg='white')
self.HAUFEING.insert(0, el["haeufigkeit"])
self.HAUFEING.grid(column=1, row=4)
#--------- row 5 -----------
#self.ist_wrt = tk.StringVar() # Datum: Letzte Durchführung
dbdatum = el["wann"]
dbm = dbdatum.find("-", 6)
dbd = dbdatum[dbm+1:] + "." + str(dbdatum[5:dbm]) + "." + str(dbdatum[:4])
self.IST_EING = tk.Entry(self.FRMEINGAB, textvariable=self.ist_wrt, bg='white')
self.IST_EING.insert(0, dbd)
self.IST_EING.grid(column=1, row=5)
#--------- row 6 Frame 'Prüfung' -----------
for val, txt in self.pruefwerte: # (int,str)
if el["pruefen"] == txt:
self.prufwrt.set(val)
break
self.PRUFEING = {} # leeres Dict
for val, txt in self.pruefwerte: # (int,str)
self.PRUFEING[val] = tk.Radiobutton(self.FRMPRUEFG, text=txt, padx=5, pady=2,
variable=self.prufwrt, value=val)
self.PRUFEING[val].grid(column=0, row=val+1, sticky=tk.W)
if val == self.prufwrt.get():
self.PRUFEING[val].select()
#---- Prüfdatei ----
if "testen" in el:
self.testwrt.set(el["testen"])
else:
self.testwrt.set("")
print("testwrt = " + self.testwrt.get())
self.TESTEING = tk.Entry(self.FRMPRUEFG, textvariable=self.testwrt, bg='white')
#self.TESTEING.delete(0, tk.END)
self.TESTEING.insert(0, self.testwrt)
self.TESTEING.grid(column=4, row=2)
#--------- row 7 Frame 'Machen' -----------
if el["machen"] == "manuell":
self.machwrt.set(0)
self.skrpwrt.set("")
else:
self.machwrt.set(1)
self.skrpwrt.set(el["machen"])
self.MACHEING = {} # leeres Dict
for val, txt in self.machwerte:
self.MACHEING[val] = tk.Radiobutton(self.FRMMACHEN, text=txt, padx=5, pady=3,
variable=self.machwrt, value=val)
self.MACHEING[val].grid(column=1, row=val+1, sticky=tk.W)
if val == self.machwrt.get():
self.MACHEING[val].select()
#---- Arbeitsskript ----
self.SKRPEING = tk.Entry(self.FRMMACHEN, textvariable=self.skrpwrt, bg='white')
self.SKRPEING.insert(0, self.skrpwrt)
self.SKRPEING.grid(column=4, row=2)
#--------- row 8 -----------
self.ANLTeing = tk.Text(self.FRMEINGAB, height=3, width=80, bg='white')
self.ANLTeing.insert('1.0', el["anleitung"])
self.ANLTeing.grid(column=1, row=8, columnspan=3)
#------------ GRID = Alle aktivieren -----------
self.FRMPRUEFG.grid(column=0, row=6, columnspan=5, sticky=tk.W)
self.FRMMACHEN.grid(column=0, row=7, columnspan=5, sticky=tk.W)
self.FRMEINGAB.grid(row=0)
#------------
self.PROGENDEBUTTON = tk.Button(self.FRMSCHALT, text='Quit', bg="red",
command=self.ROOT.quit)
.grid(row=0, column=4, sticky=tk.E, padx=20, pady=4)
self.FRMSCHALT.grid(row=1)
class DatenAuswahl:
"Fenster zur Auswahl des Datensatzes"
def __init__(self):
self.fenster = tk.Tk()
self.fenster.title('Datensatz ausw?hlen')
self.MYFRAME = tk.Frame(self.fenster, borderwidth=5, relief=tk.RIDGE, pady=4)
self.satznr = tk.IntVar()
self.SATZNR_TXT = tk.Label(self.MYFRAME, text="Nummer des Termins ", padx=5, pady=9)
.grid(column=0, row=1, sticky=tk.W)
self.SATZEIN = tk.Entry(self.MYFRAME, textvariable=self.satznr, bg='white')
.grid(column=1,row=1)
self.DATENBUTTON = tk.Button(self.MYFRAME, text="Daten einlesen", bg="lightblue",
command=self.DatenLesen) #self.satznr ??
self.DATENBUTTON.grid(column=0, row=3, padx=20, pady=20)
self.MYFRAME.grid(row=0)
def DatenLesen(self):
"""Versucht, den Termin-Satz mit Nummer 'satznr' aus der Datenbank zu lesen,
danach wird das Fenster zur Datenkorrektur ge?ffnet."""
el = createTerminListe.terminAuslesen(int(self.satznr.get()))
# Ausgabe der Werte auf demn Bildschirm
for k in el.keys():
print(k + " = " + str(el[k]))
ausgabe = TerminAendern(el)
myprog = DatenAuswahl()
tk.mainloop()
The definition of the frames in the base class is simple:
class DatenFenster:
'Klasse zur Bearbeitung von Terminen'
def __init__ (self):
locale.setlocale(locale.LC_ALL, 'de_DE.utf8')
self.ROOT = tk.Tk()
self.ROOT.title("Termin erfassen")
self.FRMEINGAB = tk.Frame(self.ROOT, borderwidth=5, relief=tk.RIDGE, pady=4)
self.FRMPRUEFG = tk.Frame(self.FRMEINGAB, borderwidth=2, relief=tk.RIDGE)
self.FRMMACHEN = tk.Frame(self.FRMEINGAB, borderwidth=2, relief=tk.RIDGE)
self.FRMSCHALT = tk.Frame(self.ROOT, borderwidth=4, relief=tk.RAISED, pady=4, padx=6,
bg="orange")
--etc.---
'terminAendern' window
The Entry at 'Prüfdatei (Pfad)' is filled with a default instead of the supplied value from the database.
I have no idea where to look further (apart from the tk source, which I am not sure I can master).
I'd be happy if someone could tell me what I am missing.