PEP 8 cleanup
This commit is contained in:
parent
c2775d2c25
commit
16f1eb6b8e
@ -1,24 +1,26 @@
|
|||||||
from tkinter import *
|
from tkinter import *
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
|
||||||
status = 1 # 1 - neue Eingabe, 2 - Eingabe verarbeitet
|
status = 1 # 1 - neue Eingabe, 2 - Eingabe verarbeitet
|
||||||
|
|
||||||
def switch_status(newS: int = None):
|
|
||||||
|
def switch_status(new_status: int = None):
|
||||||
""" Verändert den globalen Status
|
""" Verändert den globalen Status
|
||||||
|
|
||||||
:param newS: neuer Statuswert
|
:param new_status: neuer Statuswert
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
global status
|
global status
|
||||||
if not newS:
|
if not new_status:
|
||||||
if status == 1:
|
if status == 1:
|
||||||
status = 2
|
status = 2
|
||||||
else:
|
else:
|
||||||
status = 1
|
status = 1
|
||||||
else:
|
else:
|
||||||
status = newS
|
status = new_status
|
||||||
update_statusbar()
|
update_statusbar()
|
||||||
|
|
||||||
|
|
||||||
def update_statusbar():
|
def update_statusbar():
|
||||||
""" Passt die Farbe der Statuszeile an den Status an.
|
""" Passt die Farbe der Statuszeile an den Status an.
|
||||||
|
|
||||||
@ -32,6 +34,7 @@ def update_statusbar():
|
|||||||
else:
|
else:
|
||||||
frame_statusbar['style'] = 'bFrame.TFrame'
|
frame_statusbar['style'] = 'bFrame.TFrame'
|
||||||
|
|
||||||
|
|
||||||
def calculate(*args):
|
def calculate(*args):
|
||||||
""" Berechnet aus der eingegebenen Länge in feet die Länge in Metern.
|
""" Berechnet aus der eingegebenen Länge in feet die Länge in Metern.
|
||||||
|
|
||||||
@ -40,7 +43,7 @@ def calculate(*args):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
stringvalue = feet.get()
|
stringvalue = feet.get()
|
||||||
stringvalue = stringvalue.replace(",",".")
|
stringvalue = stringvalue.replace(",", ".")
|
||||||
value = float(stringvalue)
|
value = float(stringvalue)
|
||||||
m_value = 0.3048 * value
|
m_value = 0.3048 * value
|
||||||
m_value = round(m_value, 2)
|
m_value = round(m_value, 2)
|
||||||
@ -50,7 +53,8 @@ def calculate(*args):
|
|||||||
pass
|
pass
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def check_entry(what : str = ""):
|
|
||||||
|
def check_entry(what: str = ""):
|
||||||
""" Validiert, ob Eingabe leer oder eine Fließkommazahl ist.
|
""" Validiert, ob Eingabe leer oder eine Fließkommazahl ist.
|
||||||
|
|
||||||
:param what: str eingegebene Zeichenkette
|
:param what: str eingegebene Zeichenkette
|
||||||
@ -70,60 +74,61 @@ def check_entry(what : str = ""):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
# Hauptfenster
|
# Hauptfenster
|
||||||
root = Tk()
|
root = Tk()
|
||||||
root.title("Feet to Meters")
|
root.title("Feet to Meters")
|
||||||
check_entry_wrapper = root.register(check_entry)
|
check_entry_wrapper = root.register(check_entry)
|
||||||
|
|
||||||
# Rahmen im Hauptfenster (aus ttk für Farbanpassung)
|
# Rahmen im Hauptfenster (aus ttk für Farbanpassung)
|
||||||
mainframe = ttk.Frame(root, padding = "3 3 12 12")
|
mainframe = ttk.Frame(root, padding="3 3 12 12")
|
||||||
|
|
||||||
mainframe.grid(column = 0, row = 0, sticky = NW)
|
mainframe.grid(column=0, row=0, sticky=NW)
|
||||||
root.columnconfigure(0, weight = 1)
|
root.columnconfigure(0, weight=1)
|
||||||
root.rowconfigure(0, weight = 1)
|
root.rowconfigure(0, weight=1)
|
||||||
|
|
||||||
# Eingabefeld für Länge in feet
|
# Eingabefeld für Länge in feet
|
||||||
feet = StringVar()
|
feet = StringVar()
|
||||||
feet_entry = ttk.Entry(mainframe, width = 7, textvariable = feet,
|
feet_entry = ttk.Entry(mainframe, width=7, textvariable=feet,
|
||||||
validatecommand = (check_entry_wrapper, '%P'),
|
validatecommand=(check_entry_wrapper, '%P'),
|
||||||
validate = 'key')
|
validate='key')
|
||||||
feet_entry.grid(column = 2, row = 1, sticky = (W, E))
|
feet_entry.grid(column=2, row=1, sticky=W + E)
|
||||||
|
|
||||||
# Einheit-Label für Eingabefeld der Länge in feet
|
# Einheit-Label für Eingabefeld der Länge in feet
|
||||||
ttk.Label(mainframe, text = "feet").grid(column = 3, row = 1, sticky = W)
|
ttk.Label(mainframe, text="feet").grid(column=3, row=1, sticky=W)
|
||||||
|
|
||||||
# Label für Ausgabefeld der Länge in Metern
|
# Label für Ausgabefeld der Länge in Metern
|
||||||
ttk.Label(mainframe, text = "ist äquivalent zu").grid(column = 1, row = 2, sticky = E)
|
ttk.Label(mainframe, text="ist äquivalent zu").grid(column=1, row=2, sticky=E)
|
||||||
|
|
||||||
# Einheit-Label für Ausgabefeld der Länge in Metern
|
# Einheit-Label für Ausgabefeld der Länge in Metern
|
||||||
ttk.Label(mainframe, text = "Meter").grid(column = 3, row = 2, sticky = W)
|
ttk.Label(mainframe, text="Meter").grid(column=3, row=2, sticky=W)
|
||||||
|
|
||||||
# Ausgabefeld für Länge in Metern
|
# Ausgabefeld für Länge in Metern
|
||||||
meters = StringVar()
|
meters = StringVar()
|
||||||
meters_entry = ttk.Entry(mainframe, width = 7, textvariable = meters)
|
meters_entry = ttk.Entry(mainframe, width=7, textvariable=meters)
|
||||||
meters_entry.grid(column = 2, row = 2, sticky = (W,E))
|
meters_entry.grid(column=2, row=2, sticky=(W, E))
|
||||||
meters_entry.configure(state = 'readonly') # keine Eingabe, aber selektierbar
|
meters_entry.configure(state='readonly') # keine Eingabe, aber selektierbar
|
||||||
|
|
||||||
# Button für Berechnung
|
# Button für Berechnung
|
||||||
|
|
||||||
button_calc = ttk.Button(mainframe, text = "Berechne", command = calculate)
|
button_calc = ttk.Button(mainframe, text="Berechne", command=calculate)
|
||||||
button_calc.grid(column = 3, row = 3, sticky = W)
|
button_calc.grid(column=3, row=3, sticky=W)
|
||||||
|
|
||||||
# schönere Abstände
|
# schönere Abstände
|
||||||
for child in mainframe.winfo_children():
|
for child in mainframe.winfo_children():
|
||||||
child.grid_configure(padx = 5, pady = 5)
|
child.grid_configure(padx=5, pady=5)
|
||||||
|
|
||||||
# Statusbar
|
# Statusbar
|
||||||
s = ttk.Style()
|
s = ttk.Style()
|
||||||
s.configure('aFrame.TFrame', background = "yellow")
|
s.configure('aFrame.TFrame', background="yellow")
|
||||||
s.configure('bFrame.TFrame', background = "green")
|
s.configure('bFrame.TFrame', background="green")
|
||||||
s.configure('cFrame.TFrame', background = "red")
|
s.configure('cFrame.TFrame', background="red")
|
||||||
frame_statusbar = ttk.Frame(root)
|
frame_statusbar = ttk.Frame(root)
|
||||||
frame_statusbar['relief'] = 'sunken'
|
frame_statusbar['relief'] = 'sunken'
|
||||||
frame_statusbar['height'] = 12
|
frame_statusbar['height'] = 12
|
||||||
frame_statusbar['style'] = 'aFrame.TFrame'
|
frame_statusbar['style'] = 'aFrame.TFrame'
|
||||||
frame_statusbar.grid_propagate(0) # Feste Größe an Grid-Packer weitergeben
|
frame_statusbar.grid_propagate(0) # Feste Größe an Grid-Packer weitergeben
|
||||||
frame_statusbar.grid(column = 0, row = 1, sticky = W+S+E)
|
frame_statusbar.grid(column=0, row=1, sticky=W + S + E)
|
||||||
|
|
||||||
# Setze Fokus in Eingabefeld
|
# Setze Fokus in Eingabefeld
|
||||||
feet_entry.focus()
|
feet_entry.focus()
|
||||||
|
Loading…
Reference in New Issue
Block a user