Ich will bei python 2.7 eine eingabe beim Text wigdet schreiben aber utf-8.
also bei meinen Prog. klappen die Umlaute nicht.
bei python 3.x lief es ohne Probleme,
aber ich brauche es bei python 2.7
Code:
Code: Alles auswählen
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from Tkinter import*
import Tkinter
import Tkinter as Tk
import os
import string
from tkColorChooser import askcolor
###################################################################################
root = Tkinter.Tk()
root.title("Neue Notiz eintragen")
root.geometry('560x400')
root.maxsize(900,500)
root.minsize(770,450)
root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(),
root.winfo_screenheight()))
#####################################################################################
def save():
save = open("desknotiz.txt", 'w')
save.write(etext.get(0.0, 'end'))
#.encode('utf-8')
save.close()
######################################################################################
def ask_quit():
root.destroy()
root.mainloop()
##################################################################################
def setTxTColor():
(triple, hexstr) = tkinter.colorchooser.askcolor(color="#000000")
if hexstr:
temp = open(r'daten.cfd')
txtcolor = temp.readlines()
temp.close()
try:
txtcolor[2] = hexstr
except:
txtcolor = "#000000"
farbauswahl.config(bg = hexstr)
farbe = open(r'daten.cfd', 'w')
farbe.writelines(txtcolor)
farbe.close()
save()
######################################################
def textgrousse(event):
etext.config(font = ("Arial", regler1.get()))
########################################################
def cofigfile(event):
zeit = regler.get()
temp = open(r'daten.cfd')
aktualisirungtime = temp.readlines()
temp.close()
aktualisirungtime[0] = (str(zeit) + "\n")
aktualisirung = open(r'daten.cfd', 'w')
aktualisirung.writelines(aktualisirungtime)
aktualisirung.close()
save()
##########################################################
def cofigfilegr(event):
gr = "10"
gr = varZahl.get()
temp = open(r'daten.cfd')
schriftgr = temp.readlines()
schriftgr[1] = (str(gr) + "\n")
gruosse = open(r'daten.cfd', 'w')
gruosse.writelines(schriftgr)
gruosse.close()
save()
##############################################################
def openfile():
externesProgramm = "Notizdesk.exe"
os.system(externesProgramm)
########################################################
schrift = Tkinter.Label(root, text = "Schriftgr\xf6\xdfe:")
schrift.place(relx=0.01, rely=0.005)
regler1 = Scale(root,from_=8, to=40, orient=HORIZONTAL, command = textgrousse)
regler1.set(10)
regler1.place(relx=0.09, rely=0.00, relwidth=0.15)
##########################################################
scrollbar = Scrollbar(root)
scrollbar.pack( side = RIGHT, fill=Y )
etext = Text(root,yscrollcommand=scrollbar.set)
scrollbar.config(command=etext.yview)
etext.config(font =("Arial", 11))
etext.config(fg="black")
file = open('desknotiz.txt', 'r')
text = file.read()
etext.insert(INSERT, "" + text )
file.close()
scrollbar.place(relx=0.9602, rely=0.08, relheight=0.55)
etext.place(relx=0.01, rely=0.08, relwidth=0.95, relheight=0.55)
############################################################
#Daten lesen
readtools = open('daten.cfd', 'r')
aktuallisierungstime = readtools.readline()
schriftsize1 = readtools.readline()
schriftsize = schriftsize1.replace("\n", "")
############################################################
optionen = LabelFrame(root, text="Optionen f\xfcr die Anzeige auf den Desktop")
optionen.place(relx=0.01, rely = 0.64, relwidth = 0.9, relheight = 0.26)
######################################################################
try:
farbauswahl = Button(optionen,text = "",command = setTxTColor)
colorreplace = readtools.readline()
color = colorreplace.replace("\n", "")
farbauswahl.config(bg = color)
except:
color = "#000000"
##############################################################
time = Tkinter.Label(optionen, text = "Aktualisierungszeit in Sekunden")
time.place(relx=0.04, rely=0.07)
regler = Scale(optionen,from_=1, to=120, orient=HORIZONTAL, command = cofigfile)
regler.set(aktuallisierungstime)
regler.place(relx=0.04, rely=0.22, relwidth=0.25)
Schriftgr = Tkinter.Label(optionen, text = "Schriftgr\xf6\xdfe")
Schriftgr.place(relx=0.04, rely=0.6)
gruosse = ["4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "13", "14", "15", "16", "17", "18", "19", "20"]
varZahl = Tkinter.StringVar()
op = Tkinter.OptionMenu(optionen, varZahl, *gruosse, command = cofigfilegr)
varZahl.set(schriftsize)
op.place(relx=0.04, rely=0.78, relwidth=0.08, relheight = 0.2)
Schriftfarbe = Tkinter.Label(optionen, text = "Schriftfarbe")
Schriftfarbe.place(relx=0.15, rely=0.6)
farbauswahl.config(bg = color)
farbauswahl.place(relx=0.15, rely=0.8008, relwidth=0.08, relheight = 0.16)
##############################################################################################
ok = Button(root,text = "OK",command = save)
ok.place(relx=0.04, rely=0.92, relwidth=0.15, relheight=0.06)
#####################################
openprog = Button(root,text = "Anzeigen",command = open)
openprog.place(relx=0.3, rely=0.92, relwidth=0.15, relheight=0.06)
#####################################
close = Button(root,text = "Schlie\xdfen",command = ask_quit)
close.place(relx=0.7, rely=0.92, relwidth=0.15, relheight=0.06)
root.mainloop()
#########################################################################################