设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
查看: 6894|回复: 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

好友

11万

积分

管理员

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-5-2 04:33 , Processed in 0.025213 second(s), 23 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部