Verstehe Fehlermeldung nicht
Verfasst: Mittwoch 8. September 2021, 19:21
hallo,
zuerst den Code:
import tkinter as tk
from functools import partial
def count_call_back(count_label,time_base, led_blinker, counter_value=1):
count_label["text"] = counter_value
count_label.after(int(time_base*1000), count_call_back, count_label, led_blinker, counter_value + 1,time_base)
switch_label_color(counter_value, led_blinker)
def switch_label_color(counter_value, led_blinker):
if counter_value % 2 == 1: # Farbumschlag des Labels
color = "green"
else:
color = "red"
led_label["bg"] = color
def start_action(count_label,led_blinker,eingabe1): # Zeitbasis wird erzeugt, Eingabefehler abgefangen
try:
time_base = float(eingabe1.get())
except ValueError:
count_label['text'] = "Nur Zahlen!"
else:
count_call_back(count_label,led_blinker,time_base)
def main():
root = tk.Tk()
root.title(" Zeit-Zähler und Blinker ")
root.minsize(width=600, height=500)
count_label = tk.Label(root, fg="green",bg="white",font=("Arial", 22),width=10,height=2)
count_label.pack(padx=10, pady=10)
led_blinker=tk.Label(root,text="LED",font=("Arial",14), width=10,height=3 )
led_blinker.pack(padx=20, pady= 20)
text1_label=tk.Label(root,text=" Zeitbasis > 0.09 Sek. eingeben",fg="blue")
text1_label.pack()
eingabe1=tk.Entry(root)
eingabe1.pack()
start_button=tk.Button(root,text=" Start ",fg="blue",bg="yellow",width=20,command=partial(start_action,count_label, led_blinker,eingabe1))
start_button.pack(padx=20,pady=85)
ende_button=tk.Button(root, text="Ende", fg="red", bg="white",width=20,height=1, command=root.destroy).pack(padx=20, pady=80)
root.mainloop()
if __name__ == "__main__":
main()
----------------------------------------------------------------------
folgende Fehler-Meldung :
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "C:\Users\rewel\Documents\Python\Demo\g-test.10xx.py", line 21, in start_action
count_call_back(count_label,led_blinker,time_base)
File "C:\Users\rewel\Documents\Python\Demo\g-test.10xx.py", line 5, in count_call_back
count_label.after(int(time_base*1000), count_call_back, count_label, led_blinker, counter_value + 1,time_base)
TypeError: unsupported operand type(s) for *: 'Label' and 'int'
>>>
vielleicht weiss jemand rat ?
zuerst den Code:
import tkinter as tk
from functools import partial
def count_call_back(count_label,time_base, led_blinker, counter_value=1):
count_label["text"] = counter_value
count_label.after(int(time_base*1000), count_call_back, count_label, led_blinker, counter_value + 1,time_base)
switch_label_color(counter_value, led_blinker)
def switch_label_color(counter_value, led_blinker):
if counter_value % 2 == 1: # Farbumschlag des Labels
color = "green"
else:
color = "red"
led_label["bg"] = color
def start_action(count_label,led_blinker,eingabe1): # Zeitbasis wird erzeugt, Eingabefehler abgefangen
try:
time_base = float(eingabe1.get())
except ValueError:
count_label['text'] = "Nur Zahlen!"
else:
count_call_back(count_label,led_blinker,time_base)
def main():
root = tk.Tk()
root.title(" Zeit-Zähler und Blinker ")
root.minsize(width=600, height=500)
count_label = tk.Label(root, fg="green",bg="white",font=("Arial", 22),width=10,height=2)
count_label.pack(padx=10, pady=10)
led_blinker=tk.Label(root,text="LED",font=("Arial",14), width=10,height=3 )
led_blinker.pack(padx=20, pady= 20)
text1_label=tk.Label(root,text=" Zeitbasis > 0.09 Sek. eingeben",fg="blue")
text1_label.pack()
eingabe1=tk.Entry(root)
eingabe1.pack()
start_button=tk.Button(root,text=" Start ",fg="blue",bg="yellow",width=20,command=partial(start_action,count_label, led_blinker,eingabe1))
start_button.pack(padx=20,pady=85)
ende_button=tk.Button(root, text="Ende", fg="red", bg="white",width=20,height=1, command=root.destroy).pack(padx=20, pady=80)
root.mainloop()
if __name__ == "__main__":
main()
----------------------------------------------------------------------
folgende Fehler-Meldung :
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "C:\Users\rewel\Documents\Python\Demo\g-test.10xx.py", line 21, in start_action
count_call_back(count_label,led_blinker,time_base)
File "C:\Users\rewel\Documents\Python\Demo\g-test.10xx.py", line 5, in count_call_back
count_label.after(int(time_base*1000), count_call_back, count_label, led_blinker, counter_value + 1,time_base)
TypeError: unsupported operand type(s) for *: 'Label' and 'int'
>>>
vielleicht weiss jemand rat ?