Python Forum
Tkinter: How to assign calculated value to a Label
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter: How to assign calculated value to a Label
#1
I'm using Python3.8 for my raspberry pi4 project. I have a GUI that initially displays the label within a grid. I also have a button that when clicked, should display the calculated value of CO2 in the label. However, it does not display the CO2 value and there is no error flagged. Below is my code snippet (I removed others as they're not relevant to this question):

frame2 = Frame(root)
lblCo2 = Label(frame2, text="CO2 (ppm)")
lblCo2.grid(row=4, sticky=W)
valCo2 = Label(frame2, bg="white", width=12)
valCo2grid(row=4, column=1, sticky=W)

btnStart = Button(frame2, text="Start", command=btnStart_callback)
btnStart.grid(row=5, column=1, sticky=W)
frame2.pack()

def btnStart_callback():
    CycleCO2()

def CycleCO2():
    Cmd1 = [0xFE, 0x44, 0x00, 0x08, 0x02, 0x9F, 0x25)
    high = Cmd1[3]
    low = Cmd1[4]
    co2 = (high*256) + low
    
    valCo2 = tk.Label(frame2, text=co2)
Appreciate any help.
Reply


Messages In This Thread
Tkinter: How to assign calculated value to a Label - by LoneStar - Sep-01-2020, 06:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter: An image and label are not appearing. emont 7 410 Mar-21-2024, 03:00 PM
Last Post: deanhystad
  tkinter destroy label inside labelFrame Nick_tkinter 3 4,482 Sep-17-2023, 03:38 PM
Last Post: munirashraf9821
  [Tkinter] Updating Tkinter label using multiprocessing Agusms 6 3,054 Aug-15-2022, 07:10 PM
Last Post: menator01
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 4,672 Jun-26-2022, 06:26 PM
Last Post: menator01
  tkinter: Image to Label Maryan 10 5,122 Oct-29-2020, 01:48 PM
Last Post: joe_momma
  Tkinter - How can I extend a label widget? TurboC 2 2,735 Oct-13-2020, 12:15 PM
Last Post: zazas321
  changing tkinter label from thread nanok66 3 7,217 Jun-07-2020, 01:37 AM
Last Post: nanok66
  [Tkinter] tkinter How to pass label fiilename to another module? johnjh 0 1,974 Apr-17-2020, 11:34 PM
Last Post: johnjh
  Make Label Text background (default color) transparent using tkinter in python barry76 1 23,481 Nov-28-2019, 10:19 AM
Last Post: Larz60+
  Spacing Between two labels are very far and Top label is not in Center using Tkinter barry76 2 7,006 Jul-30-2019, 10:49 AM
Last Post: wuf

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020