mehrer Timer gleichzeitig
Verfasst: Sonntag 10. Januar 2021, 17:40
Hallo,
ich bin am Verzweifeln.
Ich möchte mehrer Timer gleichzeitig laufen lassen, aber irgenwie bin ich zu Doof dazu.
Es öffnen sich schon mal mehrer Fenster , was ja so gar nicht gewollt ist.
Vieleicht könnte sich einer meinen "grottenschlechten Quelltext" ansehen und sagen wo der Denkfehler ist.
P.S. bin blutiger Anfänger .
import time
import tkinter as tk
from tkinter import *
from tkinter import messagebox
from multiprocessing import Process
# creating Tk window
root = Tk()
root.geometry("1200x600")
root.title("Timerversuch")
# variablen
mhour=StringVar()
mminute=StringVar()
msecond=StringVar()
mthour=StringVar()
mtminute=StringVar()
mtsecond=StringVar()
# startwerte
mhour.set("00")
mminute.set("00")
msecond.set("05")
mthour.set("00")
mtminute.set("00")
mtsecond.set("10")
# Eingabeposition T1
mhourEntry= Entry(root, width=3, font=("Arial",18,""), textvariable=mhour)
mhourEntry.place(x=50,y=220)
mminuteEntry= Entry(root, width=3, font=("Arial",18,""), textvariable=mminute)
mminuteEntry.place(x=100,y=220)
msecondEntry= Entry(root, width=3, font=("Arial",18,""), textvariable=msecond)
msecondEntry.place(x=150,y=220)
# Eingabeposition T2
mthourEntry= Entry(root, width=3, font=("Arial",18,""), textvariable=mthour)
mthourEntry.place(x=50,y=280)
mtminuteEntry= Entry(root, width=3, font=("Arial",18,""), textvariable=mtminute)
mtminuteEntry.place(x=100,y=280)
mtsecondEntry= Entry(root, width=3, font=("Arial",18,""), textvariable=mtsecond)
mtsecondEntry.place(x=150,y=280)
#Berechnung 1
def func1():
try:
mtemp = int(mhour.get())*3600 + int(mminute.get())*60 + int(msecond.get())
except:
print("Please input the right value")
while mtemp >-1:
mmins,msecs = divmod(mtemp,60)
mhours=0
if mmins >60:
mhours, mmins = divmod(mmins, 60)
mhour.set("{0:2d}".format(mhours))
mminute.set("{0:2d}".format(mmins))
msecond.set("{0:2d}".format(msecs))
root.update()
time.sleep(1)
if (mtemp == 0):
messagebox.showinfo("Hinweis", "Zeit 1 abgelaufen ", )
mtemp -= 1
#Berechnung 2
def func2():
try:
mttemp = int(mthour.get())*3600 + int(mtminute.get())*60 + int(mtsecond.get())
except:
print("Please input the right value")
while mttemp >-1:
mtmins,mtsecs = divmod(mttemp,60)
mthours=0
if mtmins >60:
mthours, mtmins = divmod(mtmins, 60)
mthour.set("{0:2d}".format(mthours))
mtminute.set("{0:2d}".format(mtmins))
mtsecond.set("{0:2d}".format(mtsecs))
root.update()
time.sleep(1)
if (mttemp == 0):
messagebox.showinfo("Hinweis", "Zeit 2 abgelaufen ")
mttemp -= 1
mbtn = Button(root, text='Zeit 1', bd='5',
command= func1)
mbtn.place(x = 55,y = 250)
tbtn = Button(root, text='Zeit 2', bd='5',
command= func2)
tbtn.place(x = 55,y = 310)
if __name__ == '__main__':
p1 = Process(target=func1)
p1.start()
p2 = Process(target=func2)
p2.start()
p1.join()
p2.join()
root.mainloop()
ich bin am Verzweifeln.
Ich möchte mehrer Timer gleichzeitig laufen lassen, aber irgenwie bin ich zu Doof dazu.
Es öffnen sich schon mal mehrer Fenster , was ja so gar nicht gewollt ist.
Vieleicht könnte sich einer meinen "grottenschlechten Quelltext" ansehen und sagen wo der Denkfehler ist.
P.S. bin blutiger Anfänger .
import time
import tkinter as tk
from tkinter import *
from tkinter import messagebox
from multiprocessing import Process
# creating Tk window
root = Tk()
root.geometry("1200x600")
root.title("Timerversuch")
# variablen
mhour=StringVar()
mminute=StringVar()
msecond=StringVar()
mthour=StringVar()
mtminute=StringVar()
mtsecond=StringVar()
# startwerte
mhour.set("00")
mminute.set("00")
msecond.set("05")
mthour.set("00")
mtminute.set("00")
mtsecond.set("10")
# Eingabeposition T1
mhourEntry= Entry(root, width=3, font=("Arial",18,""), textvariable=mhour)
mhourEntry.place(x=50,y=220)
mminuteEntry= Entry(root, width=3, font=("Arial",18,""), textvariable=mminute)
mminuteEntry.place(x=100,y=220)
msecondEntry= Entry(root, width=3, font=("Arial",18,""), textvariable=msecond)
msecondEntry.place(x=150,y=220)
# Eingabeposition T2
mthourEntry= Entry(root, width=3, font=("Arial",18,""), textvariable=mthour)
mthourEntry.place(x=50,y=280)
mtminuteEntry= Entry(root, width=3, font=("Arial",18,""), textvariable=mtminute)
mtminuteEntry.place(x=100,y=280)
mtsecondEntry= Entry(root, width=3, font=("Arial",18,""), textvariable=mtsecond)
mtsecondEntry.place(x=150,y=280)
#Berechnung 1
def func1():
try:
mtemp = int(mhour.get())*3600 + int(mminute.get())*60 + int(msecond.get())
except:
print("Please input the right value")
while mtemp >-1:
mmins,msecs = divmod(mtemp,60)
mhours=0
if mmins >60:
mhours, mmins = divmod(mmins, 60)
mhour.set("{0:2d}".format(mhours))
mminute.set("{0:2d}".format(mmins))
msecond.set("{0:2d}".format(msecs))
root.update()
time.sleep(1)
if (mtemp == 0):
messagebox.showinfo("Hinweis", "Zeit 1 abgelaufen ", )
mtemp -= 1
#Berechnung 2
def func2():
try:
mttemp = int(mthour.get())*3600 + int(mtminute.get())*60 + int(mtsecond.get())
except:
print("Please input the right value")
while mttemp >-1:
mtmins,mtsecs = divmod(mttemp,60)
mthours=0
if mtmins >60:
mthours, mtmins = divmod(mtmins, 60)
mthour.set("{0:2d}".format(mthours))
mtminute.set("{0:2d}".format(mtmins))
mtsecond.set("{0:2d}".format(mtsecs))
root.update()
time.sleep(1)
if (mttemp == 0):
messagebox.showinfo("Hinweis", "Zeit 2 abgelaufen ")
mttemp -= 1
mbtn = Button(root, text='Zeit 1', bd='5',
command= func1)
mbtn.place(x = 55,y = 250)
tbtn = Button(root, text='Zeit 2', bd='5',
command= func2)
tbtn.place(x = 55,y = 310)
if __name__ == '__main__':
p1 = Process(target=func1)
p1.start()
p2 = Process(target=func2)
p2.start()
p1.join()
p2.join()
root.mainloop()