请选择 进入手机版 | 继续访问电脑版
设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
查看: 6651|回复: 1

关于获取tkinter.Text所输入文本的疑问

[复制链接]

4

主题

0

好友

40

积分

新手上路

Rank: 1

发表于 2017-8-13 22:06:57 |显示全部楼层
Python的版本是3.6,代码如下
from tkinter import *
def p():
    print(text1.get(0))

root=Tk()
text1 = Text(root)
b=Button(root,text="按钮3",command=p)
root.mainloop()

运行后在文本框内输入文字,再按下Button后,报错:
    print(text1.get(0))
AttributeError: 'NoneType' object has no attribute 'get'

查看有关的资料,应该是用get方法没错啊
get(startindex [,endindex])
This method returns a specific character or a range of text.
求crossin先生指导


P.S.如果想要把原程序中print的信息实时反馈在tkinter的界面中,是使用Text.insert的方法吗?
回复

使用道具 举报

174

主题

45

好友

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

发表于 2017-8-14 19:50:31 |显示全部楼层
'NoneType' object has no attribute 'get'
是说你的 text1 是个 None

你函数没有传参数,也没有用全局变量
#==== Crossin的编程教室 ====#
微信ID:crossincode
网站:http://crossincode.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-3-29 20:39 , Processed in 0.022489 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部