如何在带有 IntVar 的标签中使用小数点

How use decimal in a label with IntVar on tkinter

from tkinter import *
v=Tk()
v.geometry("400x400")
a= IntVar()
a.set(5.494949)


l=Label(textvariable= a)
l.pack()

我使用这个和 return 带有 5.494949 的标签,我需要 5.49

这可能会有所帮助:)

from tkinter import *
v=Tk()
v.geometry("400x400")
a= IntVar()
# round function simply rounds the var upto given number of decimal places in the function argument
a.set(round(5.494949,2))

l=Label(textvariable= a)
l.pack()

您想要的内容没有明确的支持。但是,您可以使用 StringVar 或直接设置标签的值:

l = Label(text="%.2f" % 5.494949)
...
l.configure(text="%.2f" % 3.14159)