irgendwie habe ich gerade ein Brett vorm Kopf und mittlerweile soviel gelesen, dass ich selber nicht mehr weiß was ich tu. Vielleicht kann mir jemand das Brett vom Kopf ziehen und mir beim Problem helfen.
Appropos ... ich bin weder Programmierer noch musste ich mich in den vergangenen Jahren intensiv mit Coding auseinander setzen. Aber Zeiten ändern sich.
Zum Problem: In der GUI soll die Möglichkeit gegeben sein einen Temperaturwert einzugeben, der den vorgegeben Startwert überschreibt. Dass ganze soll mit Return oder Button zu bestätigen sein und anschließend ausgegeben werden. Soweit so gut, jetzt das eigentliche Problem: ich benötige entweder den definierten Startwert oder wenn eine Eingabe erfolgt ist, den eigegebenen Wert als Grundlage für weitere Berechnungen. Ich bekomme ihn aber nicht zurück? Wo liegt mein Denkfehler? Wenn ich versuche TBase mit Return zurückzugeben, krieg ich nur Fehlermeldung.
Danke im Voraus.
Code: Alles auswählen
import tkinter as tk
from tkinter import font
wintemp1 = tk.Tk()
wintemp1.geometry('600x200')
font_primary = font.Font(family="Arial", size=20, underline=True)
font_secondary = font.Font(family="Arial", size=10)
temp_mat1 = tk.IntVar()
temp_mat1.set(20)
tinput_label = tk.Label(wintemp1, text="Temperatureingabe:", font=font_secondary)
tinput_label.place(x=20, y=20, width=180, height=20)
tinput1_entry = tk.Entry(wintemp1, font=font_secondary, borderwidth=2, justify="center")
tinput1_entry.place(x=200, y=20, width=50, height=20)
tinput2_label = tk.Label(wintemp1, text="°C", font=font_secondary)
tinput2_label.place(x=250, y=20, width=30, height=20)
def onReturn(*event):
try:
TBase = float(tinput1_entry.get())
temp_mat1.set(int(TBase))
except:
temp_mat1.set('ERROR')
tinput1_entry.bind('<Return>', onReturn)
def temp_101():
try:
TBase = float(tinput1_entry.get())
temp_mat1.set(int(TBase))
except:
temp_mat1.set('ERROR')
tinput3_label = tk.Label(wintemp1, textvariable=temp_mat1, font=font_secondary)
tinput3_label.place(x=450, y=20, width=50, height=20)
temp_mat2 = tk.Button(wintemp1, text="Enter", font=font_secondary, command=temp_101)
temp_mat2.place(x=320, y=20, width=70, height=20)
temp_mat3 = tk.Button(wintemp1, text="Enter", font=font_secondary, command=onReturn)
temp_mat3.focus_set()
wintemp1.mainloop()