Button mit Timerzeit als Text
Verfasst: Mittwoch 25. März 2020, 01:35
Hi
Ich dreh fast durch
Wie zum Geier kann man ein print() auf einen Button übergeben ?
Das soll statt in der Kommandozeile auf einem Button sein. Buttons sehen wie folgt aus ( ja nun gibts mecker wegen * und ... aber das ist das Rohkonstrukt, jeder Button hat eine andere Größe, Farbe und Schrift, andere Rahmen usw. daher lieber 8 mal als Global und "kann ich den davor nochmal sehen ? ".
Der #-Code ist einer von etwa 50 Versuchen und es klappt dennoch net. Mann wünsche ich mir ne Option "Import from JavaScript", dann wäre das Problem in 20 Minuten gelöst.
Also wenn jemand eine Idee hat was ich da ändern könnte ... schonmal vielen Dank.
Ich dreh fast durch

Code: Alles auswählen
seconds = 10
minutes = 1
hours = 1
import time
while True:
print(str(hours) + ":" + str(minutes).zfill(2) + ":" + str(seconds).zfill(2))
seconds = seconds - 1
time.sleep(1)
if seconds == -1:
seconds = 59
minutes = minutes - 1
if minutes == -1:
minutes = 59
hours = hours - 1
Code: Alles auswählen
from tkinter import *
# lib laden
# nun mal Oberfläche basteln und Hintergrund festlegen
root = Tk()
root.wm_title("TR3000")
root.geometry("600x1024")
root.config(cursor="none")
mainFrame = Frame(root, background = "#000000", width = 600, heigh = 1024)
mainFrame.grid(row = 0, column = 0, padx = 0, pady = 0)
buttonFrame = Frame( mainFrame, background="#000000")
buttonFrame.grid(row = 1, column = 0, padx = 0, pady = 20)
def buildGUI1():
B1 = Button(buttonFrame, text = "Start", bg = "#00ff00", width = 6, heigh = 1, font =("arial", 46))
B1.grid(row = 0, column = 1, padx = 65, pady = 3)
# B1.pack()
def button_click1(event):
if B1["text"]=="Start":
B1["text"]="Stopp"
B1["background"]="red"
buildTM1()
else:
B1["text"]="Start"
B1["background"]="#00ff00"
B1.bind("<Button-1>", button_click1)
buildGUI1()
def buildGUI2():
B2 = Button(buttonFrame, text = "Start", bg = "#00ff00", width = 6, heigh = 1, font =("arial", 46))
B2.grid(row = 1, column = 1, padx = 65, pady = 3)
# B1.pack()
def button_click2(event):
if B2["text"]=="Start":
B2["text"]="Stopp"
B2["background"]="red"
else:
B2["text"]="Start"
B2["background"]="#00ff00"
B2.bind("<Button-1>", button_click2)
buildGUI2()
def buildGUI3():
B3 = Button(buttonFrame, text = "Start", bg = "#00ff00", width = 6, heigh = 1, font =("arial", 46))
B3.grid(row = 2, column = 1, padx = 65, pady = 3)
# B1.pack()
def button_click3(event):
if B3["text"]=="Start":
B3["text"]="Stopp"
B3["background"]="red"
else:
B3["text"]="Start"
B3["background"]="#00ff00"
B3.bind("<Button-1>", button_click3)
buildGUI3()
def buildGUI4():
B4 = Button(buttonFrame, text = "Start", bg = "#00ff00", width = 6, heigh = 1, font =("arial", 46))
B4.grid(row = 3, column = 1, padx = 65, pady = 3)
# B1.pack()
def button_click4(event):
if B4["text"]=="Start":
B4["text"]="Stopp"
B4["background"]="red"
else:
B4["text"]="Start"
B4["background"]="#00ff00"
B4.bind("<Button-1>", button_click4)
buildGUI4()
def buildGUI5():
B5 = Button(buttonFrame, text = "Start", bg = "#00ff00", width = 6, heigh = 1, font =("arial", 46))
B5.grid(row = 4, column = 1, padx = 65, pady = 3)
# B1.pack()
def button_click5(event):
if B5["text"]=="Start":
B5["text"]="Stopp"
B5["background"]="red"
else:
B5["text"]="Start"
B5["background"]="#00ff00"
B5.bind("<Button-1>", button_click5)
buildGUI5()
def buildGUI6():
B6 = Button(buttonFrame, text = "Start", bg = "#00ff00", width = 6, heigh = 1, font =("arial", 46))
B6.grid(row = 5, column = 1, padx = 65, pady = 3)
# B1.pack()
def button_click6(event):
if B6["text"]=="Start":
B6["text"]="Stopp"
B6["background"]="red"
else:
B6["text"]="Start"
B6["background"]="#00ff00"
B6.bind("<Button-1>", button_click6)
buildGUI6()
def buildGUI7():
B7 = Button(buttonFrame, text = "Start", bg = "#00ff00", width = 6, heigh = 1, font =("arial", 46))
B7.grid(row = 6, column = 1, padx = 65, pady = 3)
# B1.pack()
def button_click7(event):
if B7["text"]=="Start":
B7["text"]="Stopp"
B7["background"]="red"
else:
B7["text"]="Start"
B7["background"]="#00ff00"
B7.bind("<Button-1>", button_click7)
buildGUI7()
def buildGUI8():
B8 = Button(buttonFrame, text = "Start", bg = "#00ff00", width = 6, heigh = 1, font =("arial", 46))
B8.grid(row = 7, column = 1, padx = 65, pady = 3)
# B1.pack()
def button_click8(event):
if B8["text"]=="Start":
B8["text"]="Stopp"
B8["background"]="red"
else:
B8["text"]="Start"
B8["background"]="#00ff00"
B8.bind("<Button-1>", button_click8)
buildGUI8()
#def buildTM1():
# seconds = 0
# minutes = 0
# hours = 2
# T1 = Button(buttonFrame, text = "2:00:00", bg = "#ffffff", width = 6, heigh = 1, font =( "arial", 46))
# T1.grid(row = 0, column = 0, padx = 22, pady = 12)
# import time
# while True:
# T1["text"]=(str(hours) + ":" + str(minutes).zfill(2) + ":" + str(seconds).zfill(2))
# seconds = seconds - 1
# time.sleep(1)
# if seconds == 0:
# seconds = 59
# minutes = minutes - 1
# if minutes == 0:
# minutes = 59
# hours = hours - 1
#buildTM1()
T1 = Button(buttonFrame, text = "2:00:00", bg = "#ffffff", width = 6, heigh = 1, font =( "arial", 46))
T1.grid(row = 0, column = 0, padx = 22, pady = 12)
T2 = Button(buttonFrame, text = "2:00:00", bg = "#ffffff", width = 6, heigh = 1, font =( "arial", 46))
T2.grid(row = 1, column = 0, padx = 2, pady = 12)
T3 = Button(buttonFrame, text = "2:00:00", bg = "#ffffff", width = 6, heigh = 1, font =( "arial", 46))
T3.grid(row = 2, column = 0, padx = 2, pady = 12)
T4 = Button(buttonFrame, text = "2:00:00", bg = "#ffffff", width = 6, heigh = 1, font =( "arial", 46))
T4.grid(row = 3, column = 0, padx = 2, pady = 12)
T5 = Button(buttonFrame, text = "2:00:00", bg = "#ffffff", width = 6, heigh = 1, font =( "arial", 46))
T5.grid(row = 4, column = 0, padx = 2, pady = 12)
T6 = Button(buttonFrame, text = "2:00:00", bg = "#ffffff", width = 6, heigh = 1, font =( "arial", 46))
T6.grid(row = 5, column = 0, padx = 2, pady = 12)
T7 = Button(buttonFrame, text = "2:00:00", bg = "#ffffff", width = 6, heigh = 1, font =( "arial", 46))
T7.grid(row = 6, column = 0, padx = 2, pady = 12)
T8 = Button(buttonFrame, text = "2:00:00", bg = "#ffffff", width = 6, heigh = 1, font =( "arial", 46))
T8.grid(row = 7, column = 0, padx = 2, pady = 12)
Slider = Scale(mainFrame, from_=0, to = 120, resolution = 1, orient = HORIZONTAL, length = 500, font = ("arial",22))
Slider.grid(row = 8, padx = 0 , pady = 3)
root.mainloop()
Also wenn jemand eine Idee hat was ich da ändern könnte ... schonmal vielen Dank.