如何在tkinter中创建int项>>

问题描述 投票:2回答:1

我想创建一个面积计算器,因为我有一些空闲时间,所以我尝试先将其运行到终端中,并且可以正常工作,但是当我决定添加一个精巧的GUI时,出现了一个错误我的代码是这个

from tkinter import *
screen = Tk()
screen.title("Area of Circle Calculator")
screen.geometry("500x500")
def submit():
    global done
    pi = 3.14159265359
    an = int(pi * radius*radius)
    laod = Label(screen, text = "Hello" % (an))
    load.grid()
ask = Label(screen, text = "What is the radius of the circle?")
ask.pack()
radius = Entry(screen)
radius.pack()
done = Button(screen, text="submit", command = submit)
done.pack()
screen.mainloop()

这是我得到的错误

C:\Users\Timothy\Desktop>python aoc.py
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Timothy\AppData\Local\Programs\Python\Python37-32\lib\tkinter\_
_init__.py", line 1705, in __call__
    return self.func(*args)
  File "aoc.py", line 8, in submit
    an = int(pi * radius*radius)
TypeError: unsupported operand type(s) for *: 'float' and 'Entry'

C:\Users\Timothy\Desktop>

我尝试将int()添加到条目中,但确实有用

我想创建一个面积计算器,因为我有一些空闲时间,所以我尝试先在终端上运行它,并且它可以正常工作,但是当我决定很好地添加Lite GUI时,出现了错误,我的代码...

python tkinter
1个回答
1
投票

您需要调用radius.get()来获取Entry小部件的当前值。这里是一些documentation

© www.soinside.com 2019 - 2024. All rights reserved.