I'm having a hard time getting this to work. I have a Raspberry Pi with a 4 inch screen that I am trying to make a display that shows the time and then when you click it switches to the cpu temperature. Right now it displays right but when I click it goes into a loop of the two functions I made. Any help would be great!
from tkinter import * from tkinter import ttk from tkinter import font from gpiozero import CPUTemperature import time cpu = CPUTemperature() temp = f'{cpu.temperature}' def quit(*args): root.destroy() def mouseClicked(event): txt.set(time.strftime("%H :%M :%S")) root.after(1000,show_time) def show_time(): txt.set(time.strftime("%H :%M :%S")) root.after(1000,show_time) def show_temp(): txt.set(f'{cpu.temperature}' + ' C') root.after(1000,show_temp) root = Tk() root.attributes("-fullscreen",True) root.configure(background='black') root.bind("<Escape>",quit) root.bind("<Button-1>",mouseClicked) root.after(1000,show_temp) fnt = font.Font(family='Helvetica', size=128, weight='bold') txt = StringVar() txt.set(f'{cpu.temperature}' + ' C') lbl = ttk.Label(root, textvariable=txt, font=fnt, foreground="green", background="black") lbl.place(relx=0.5, rely=0.5, anchor=CENTER) root.mainloop()
Larz60+ write Mar-17-2021, 06:25 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.