ich habe ein kleines problem und komme nicht auf die lösung.
Code: Alles auswählen
# Setup
from tkinter import *
from tkinter import ttk
from configparser import ConfigParser
#config
cfg = ConfigParser()
cfg.read('config.ini')
def einstellung_speichern_action():
cfgfile = open("config.ini","w")
cfg.set("Stichworte", "Stichworte", stichworte_var2)
cfg.write(cfgfile)
cfgfile.close()
# Einstellungsfenster
einstellungsfenster = Tk()
einstellungsfenster.title("Einstellungen")
einstellungsfenster.geometry("400x490")
# Tabs
tabControl = ttk.Notebook(einstellungsfenster)
tab1 = ttk.Frame(tabControl)
tabControl.add(tab1, text='Stichworte')
tabControl.pack(expand=1, fill="both")
#Button
e_speichern_button = Button(einstellungsfenster, text="Speichern", command=einstellung_speichern_action)
# Stichworte
stichworte_scroll = Scrollbar (tab1)
stichworte_var2 = Text(tab1, height=10, width=50)
stichworte_scroll.pack(side=RIGHT, fill=Y)
stichworte_var2.pack(side=LEFT, fill=Y)
stichworte_scroll.config(command=stichworte_var2.yview)
stichworte_var2.config(yscrollcommand=stichworte_scroll.set)
stichworte_var2.insert(END, cfg.get("Stichworte", "Stichworte"))
e_speichern_button.pack()
# Ereignisschleife
einstellungsfenster.mainloop()
Code: Alles auswählen
[Stichworte]
Stichworte= F 1
F 2
F 2 Y
F 3
F 3 Y
F 4
F BMA
F BUS Y
F FLUG 1 Y
F FLUG 2 Y
F GAS 1
F GAS 2
F LKW
F ZUG
F ZUG Y
F RWM
F SCHIFF 1
F SCHIFF 2
F SCHIFF 2 Y
F SCHIFF 2 GEFAHR
F WALD 1
F WALD 2
H 1
H 1 Y
H 2
H ABST Y
H ELEK
H EINST Y
H FLUSS
H FLUSS Y
H WASS Y
H GAS 1
H GAS 2
H GEFAHR 1
H GEFAHR 2
H KLEMM 1 Y
H KLEMM 2 Y
H ÖL FLUSS
H ÖL WASS
H RADIOAKTIV
H SCHIFF
H SCHIFF Y
H ZUG 1 Y
H ZUG 2 Y
kann mir da einer helfen?Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\maike\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "problem.py", line 14, in einstellung_speichern_action
cfg.set("Stichworte", stichworte_var2)
File "C:\Users\maike\AppData\Local\Programs\Python\Python37-32\lib\configparser.py", line 1197, in set
self._validate_value_types(option=option, value=value)
File "C:\Users\maike\AppData\Local\Programs\Python\Python37-32\lib\configparser.py", line 1179, in _validate_value_types
raise TypeError("option keys must be strings")
TypeError: option keys must be strings