Ich habe mir nun endlich einen Raspberry Pi gekauft und wollte gleich mal in Python einsteigen. Dazu habe ich mir als Aufgabe gesetzt, ein Adressbuch zu programmieren. Alles geht soweit, nur ich komme nicht drauf, wie ich hier einen Button zum Speichern der Labels+Entries komme. Könnt ihr mir helfen?
Code: Alles auswählen
#!/usr/bin/python
#-*- coding: utf-8 -*-
import sys
import tkMessageBox
from Tkinter import *
import Tkinter as tk
import Tkinter
import tkMessageBox
root=Tkinter.Tk()
root.geometry('450x450+200+200')
root.title('Adressbuch')
center=Label(text="Adressbuch für den Raspberry Pi",fg="red").pack()
def name():
mtext=name.get()
namelabel=Label(mGui, text=name).pack()
def adresse():
mtext=adresse.get()
adresselabel=Label(mGui, text=adresse).pack()
def wohnort():
mtext=wohnort.get()
wohnortlabel=Label(mGui, text=wohnort).pack()
def telefon():
mtext=telefon.get()
telefonlabel=Label(mGui, text=telefon).pack()
def geburtstag():
mtext=geburtstag.get()
geburtstaglabel=Label(mGui, text=geburtstag).pack()
def beenden():
if tkMessageBox.askokcancel("Beenden", "Möchten Sie das Adressbuch wirklich schließen?"):
root.destroy()
root.mainloop()
nametext=Label(text="Namen eingeben:").place(x=0, y=20)
name=Entry(root, textvariable=name).place(x=200, y=20)
adressetext=Label(text="Adresse eingeben:").place(x=0, y=40)
adresse=Entry(root, textvariable=adresse).place(x=200, y=40)
wohnorttext=Label(text="Wohnort eingeben:").place(x=0, y=60)
wohnort=Entry(root, textvariable=wohnort).place(x=200, y=60)
telefontext=Label(text="Telefonnummer eingeben:").place(x=0, y=80)
telefon=Entry(root, textvariable=telefon).place(x=200, y=80)
geburtstagtext=Label(text="Geburtstag eingeben:").place(x=0, y=100)
geburtstag=Entry(root, textvariable=geburtstag).place(x=200, y=100)
exitbutton=Button(text="Adressbuch beenden", command=beenden).place(x=0, y=250)
root.mainloop()
Code: Alles auswählen
#!/usr/bin/python
#-*- coding: utf-8 -*-
import sys
print "Adressbuch für den Raspberry Pi"
n=raw_input("Namen eingeben:")
a=raw_input("Adresse eingeben:")
o=raw_input("Ort eingeben:")
t=raw_input("Telefonnummer eingeben:")
g=raw_input("Geburtstag eingeben:")
print " "
print "Der Kontakt wird in der Datei Adressbuch.txt gespeichert"
sys.stdout = open("Adressbuch.txt", "a")
print " "
print "Name: " + str(n)
print "Adresse: " + str(a)
print "Wohnort: " + str(o)
print "Telefonnummer: " + str(t)
print "Geburtstag: " + str(g)