Python Forum
Problem adding a float to a DoubleVar
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem adding a float to a DoubleVar
#1
I have declared a DoubleVar() as I need to use the variable as a textvariable for a tkinter label. However; when I try to add to it I get the error
Output:
unsupported operand type(s) for +: 'DoubleVar' and 'float'
This code is part of a function:
global dailyTotal
    dailyTotal = dailyTotal + 3.0
And dailyTotal is decalred as a DoubleVar():
dailyTotal = DoubleVar()
    dailyTotalLabel = Label(root, textvariable = dailyTotal)
Reply
#2
Use
dailyTotal.set(dailyTotal.get() + 3.0)
Reply
#3
(Apr-03-2018, 08:45 AM)Gribouillis Wrote: Use
dailyTotal.set(dailyTotal.get() + 3.0)

Thank you, that did the trick.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python calculate float plus float is incorrect? sirocawa 6 291 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  problem adding two numpy arrays djf123 2 2,098 Aug-09-2022, 08:31 PM
Last Post: deanhystad
  Django: Adding Row Data To Existing Model Instance Question/Problem. Steven_Pinkerton 1 1,249 Aug-09-2022, 10:46 AM
Last Post: Addweb
  Convert string to float problem vasik006 8 3,411 Jun-03-2022, 06:41 PM
Last Post: deanhystad
  Problem with adding arbitrary parrameters to __init__ method sebastianvdn 1 1,983 Feb-03-2020, 09:30 PM
Last Post: micseydel
  Problem adding keys/values to dictionary where keynames = "property" and "value" jasonashaw 1 2,053 Dec-17-2019, 08:00 PM
Last Post: jasonashaw
  Adding markers to Folium map only adding last element. tantony 0 2,125 Oct-16-2019, 03:28 PM
Last Post: tantony
  Comaparing Float Values of Dictionary Against A Float Value & Pick Matching Key firebird 2 3,397 Jul-25-2019, 11:32 PM
Last Post: scidam

Forum Jump:

User Panel Messages

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