如何从Tkinter的输入框中从一个函数到另一个函数获取变量

时间:2019-05-21 14:11:43

标签: python python-3.x tkinter

我正在尝试从功能内置于函数中的输入框获取数据。

from tkinter import *
def enter():
    def calculate():
        dis = et1.get()
        result = int(dis) * 1000
        et2.insert(0, result)
    global add
    add = Toplevel(root)
    add.geometry("200x200")
    et1 = Entry(add).place(x=60, y = 60)
    et2 = Entry(add).place(x = 60, y = 100)
    btn1 = Button(add, text = "Calculate", command = calculate).place(x = 60, y = 140)
    add.mainloop()

root = Tk()
root.title("Home")
root.geometry("100x100")
btn = Button(root, text = "Enter", command = enter).place(x = 50, y = 50)
root.mainloop()

单击按钮时输出显示错误消息

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Thiluxan\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "f:/Python/GUI/pro14.py", line 4, in calculate
    dis = et1.get()
AttributeError: 'NoneType' object has no attribute 'get'

0 个答案:

没有答案