wie im Titel beschrieben bin ich Python3 Anfänger. Ich versuche mir gerade die Sprache anzueignen. Ich versuche mich ausserdem gleich schon mal mit tkinter. Bitte keine Kommentare wie: "Arbeite ein Tutorial durch" oder ähnliches. ... --> Learning by doing <--- ist meine Einstellung. Denn etwas zu lernen was mich (im Moment) nicht interessiert, fällt mir ausgesprochen schwer :-/
Zu meinen Fragen:
--> Wie kann ich den Code verbessern (kürzen, performance, lesbarkeit usw).
--> Habe ich anderweitige Fehler gemacht (Logik stimmt nicht ect.).
--> Sonstige Anmerkungen. Bin sehr an eurer Kritik/Anregungen interessiert. Schliesslich möchte ich Python vernünftig nutzen.
Anmerkung zu meinem Code:
- Habe noch keine Bindings eingefügt
- Ein Entwurf, Oberfläche muss natürlich noch überarbeitet werden. Aber so ungefähr sollte die Software später aussehen.
Code: Alles auswählen
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 15 20:42:45 2016
@author: flesh
"""
from tkinter import *
import math
"""------------------------------------
Create functions for open a new Window
------------------------------------"""
# Neues Fenster öffnen bei Button-klick 'Toolsammlung'
def tools_Click():
toolsWindow = Toplevel()
toolsWindow.title('Toolsammlung')
toolsWindow.geometry('1200x450')
"""--------------
Tools Window --> 'wurzel berechnen'
--------------"""
#Frame 1 erstellen
frame1 = Frame(toolsWindow, width='1150')
frame1.pack(fill='both')
labelWurzel = Label(frame1,
text='Zahl zur Wurzelberechnung eingeben:',
font='Monospace 12', bg='white', fg='black',
width='39', justify='left')
labelWurzel.pack(side='left')
wurzelEingabe = Entry(frame1, font='Monospace 12',
bg='brown', fg='black', width='13')
wurzelEingabe.pack(side='left')
# Funktion zur Quadratwurzelberechnung
def wurzel_rechnen():
try:
awurzel = float(wurzelEingabe.get())
bwurzel = math.sqrt(awurzel)
labelErgebnisWurzel.config(text=bwurzel)
except:
labelErgebnisWurzel.config(text='Sie müssen eine Zahl eingeben!')
buttonWurzel = Button(frame1, font='Monospace 12',
bg='white', fg='black', text='OK',
command=wurzel_rechnen)
buttonWurzel.pack(side='left')
labelErgebnisWurzel = Label(frame1, font='Monospace 12',
bg='brown', fg='black', justify='left',
width='35')
labelErgebnisWurzel.pack(side='left')
"""Tools Window --> Hypothenuse rechteckiges 3eck
"""
#Frame 2
frame2 = Frame(toolsWindow, width='1150')
frame2.pack(fill='both')
def hypo_rechnen():
try:
ahypo = float(entryHypoA.get())
bhypo = float(entryHypoB.get())
c1hypo = ahypo*ahypo + bhypo*bhypo
c2hypo = math.sqrt(c1hypo)
labelHypErgebnis.config(text=c2hypo)
except:
labelHypErgebnis.config(text='Sie müssen Zahlen eingeben!')
labelHypo = Label(frame2,
text='Länge der Hypothenuse berechnen',
font='Monospace 12', bg='white', fg='black',
width='39', justify='center')
labelHypo.pack(fill='x')
labelHypozahlA = Label(frame2,
text='Gegenkatheten Länge eingeben:',
font='Monospace 12', bg='white', fg='black',
width='39', justify='left')
labelHypozahlA.pack(side='left')
entryHypoA = Entry(frame2, font='Monospace 12',
bg='brown', fg='black', width='13')
entryHypoA.pack(side='left')
labelHypozahlB = Label(frame2,
text='Ankatheten Länge eingeben:',
font='Monospace 12', bg='white', fg='black',
width='39', justify='left')
labelHypozahlB.pack(side='left')
entryHypoB = Entry(frame2, font='Monospace 12',
bg='brown', fg='black', width='13')
entryHypoB.pack(side='left')
#Frame 3
frame3 = Frame(toolsWindow, width='1150')
frame3.pack(fill='both')
buttonHypoOK = Button(frame3, font='Monospace 12',
bg='white', fg='black', text='OK',
command=hypo_rechnen)
buttonHypoOK.pack(side='left')
labelHypErgebnis = Label(frame3,
font='Monospace 12', bg='brown', fg='black',
width='39', justify='left')
labelHypErgebnis.pack(side='left')
"""
------------------------------------
Create Main Window and Widgets
------------------------------------
"""
# Create main-window
mainwindow = Tk()
mainwindow.title('Riebis-Abbundsoftware')
mainwindow.geometry('600x450')
# Create labelh1
labelh1 = Label(mainwindow, text='free Zimmerer Abbundsoftware',
font = 'Monospace 24', bg='brown', fg='black',
justify='center')
labelh1.pack(fill=X, side='top')
# Trennlinien Label erzeugen
labelTrennlinie = Label(text='------------------------------',
font='Monospace 20')
labelTrennlinie.pack(fill=X, side='top')
# Create labelbottom
labelbottom = Label(mainwindow, text='@author: Fle$h', bg='brown',
fg='black', justify='center', font='Mono 8')
labelbottom.pack(fill=X, side='bottom')
#Button1 erstellen ( Sparren berehnen )
button1Sparren = Button(text='Sparren rechnen', font='Monospace 18',
justify='center', bg='lightgrey', fg='brown',
width='35')#command = einfügen
button1Sparren.pack()
#Button2 erstellen ( Schrägsparren berechnen )
button2GiebelSparren = Button(text='Schrägen Giebelsparren rechnen',
font='Monospace 18', justify='center',
bg='lightgrey', fg='brown',
width='35') #command = einfügen
button2GiebelSparren.pack()
#Button3 erstellen ( Gratsparren berechnen )
button3Gratsparren = Button(text='Gratsparren rechnen', bg='lightgrey',
fg='brown', justify='center',
width='35', font='Monospace 18') #command = einfügen
button3Gratsparren.pack()
#Button4 erstellen ( Kehlsparren berechnen )
button4Kehlsparren = Button(text='Kehlsparren rechnen', bg='lightgrey',
fg='brown', justify='center',
font='Monospace 18', width='35') #command = einfügen
button4Kehlsparren.pack()
#Button5 erstellen ( Lattung & Eindeckung berechnen )
button5Lattung = Button(text='Lattung & Dacheindeckung rechnen',
bg='lightgrey', fg='brown', justify='center',
font='Monospace 18', width='35') #command = einfügen
button5Lattung.pack()
#Button6 erstellen ( noch offen )
button6unklar1 = Button(text='sonstiges', width='35',
bg='lightgrey', fg='brown', justify='center',
font='Monospace 18') #command = einfügen
button6unklar1.pack()
#Button7 erstellen zusatz Rechenfunktionen
button7Tools = Button(text='Toolsammlung', width='35',
bg='lightgrey', fg='brown', justify='center',
font='Monospace 18', command=tools_Click) #command = einfügen
button7Tools.pack()
#Button8 erstellen ( sonstiges )
button8Infos = Button(text='weitere Informationen', width='35',
bg='lightgrey', fg='brown', justify='center',
font='Monospace 18') #command = einfügen
button8Infos.pack()
#Button9 erstellen ( noch offen )
"""
button9drunk = Button(text='Der Entwickler ist besoffen', width='35',
bg='lightgrey', fg='brown', justify='center',
font='Monospace 18') #command = einfügen
button9drunk.pack()
"""
mainwindow.mainloop()
Bitte Kommentieren, danke --> DaRiebi