为什么返回 `None` 而不是 tkinter.Entry 对象? [英] Why is `None` returned instead of tkinter.Entry object?

查看:34
本文介绍了为什么返回 `None` 而不是 tkinter.Entry 对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Python 的新手,在四处摸索时我注意到了这一点:

I'm new to python, poking around and I noticed this:

from tkinter import *
def test1():
    root = Tk()
    txtTest1 = Entry(root).place(x=10, y=10)
    print(locals())
def test2():
    root = Tk()
    txtTest2 = Entry(root)
    txtTest2.place(x=10, y=10)#difference is this line
    print(locals())
test1()
test2()

输出包含:

'txtTest1':无

'txtTest2':

为什么 test1 有一个 None 而不是 <tkinter.Entry 对象在 ...?

Why does test1 have a None instead of <tkinter.Entry object at ...?

我使用的是 python 3.2 和 PyScripter.

I'm using python 3.2 and PyScripter.

推荐答案

Entryplace 方法不返回值.它就地作用于现有的 Entry 变量.

The place method of Entry doesn't return a value. It acts in-place on an existing Entry variable.

这篇关于为什么返回 `None` 而不是 tkinter.Entry 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆