Sep-01-2020, 06:58 PM
Post the bare minimum runnable code showing the problem at hand.
Dont use * imports see Namespace flooding with * imports
Create the label once and then change it's text value in the buttons event handler.
Use a class to easily keep a reference to GUI widgets.
See below code
Dont use * imports see Namespace flooding with * imports
Create the label once and then change it's text value in the buttons event handler.
Use a class to easily keep a reference to GUI widgets.
See below code
import tkinter as tk class Main: def __init__(self, root): self.frame = tk.Frame(root) lblCo2 = tk.Label(self.frame, text="CO2 (ppm)") lblCo2.grid(row=4, sticky=tk.W) self.valCo2 = tk.Label(self.frame, bg="white", width=12) self.valCo2.grid(row=4, column=1, sticky=tk.W) btnStart = tk.Button(self.frame, text="Start", command=self.on_btn_start) btnStart.grid(row=5, column=1, sticky=tk.W) self.frame.pack() def on_btn_start(self): Cmd1 = [0xFE, 0x44, 0x00, 0x08, 0x02, 0x9F, 0x25] high = Cmd1[3] low = Cmd1[4] co2 = (high*256) + low self.valCo2['text'] = co2 root = tk.Tk() main = Main(root) root.mainloop()