鱼C论坛

 找回密码
 立即注册
查看: 1496|回复: 6

[已解决]tkinter

[复制链接]
发表于 2020-12-18 21:43:24 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 小伤口 于 2020-12-21 13:36 编辑
  1. from tkinter import*
  2. def A():
  3.     b=ent1.get(1.0,END)
  4.     c=int(b)*2
  5.     ent2.insert(INSERT,c)
  6. root=Tk()
  7. theButton=Button(root,text='giao!',command=A)
  8. theButton.grid(row=3,column=1,sticky=E,padx=10,pady=5)
  9. ent1=Text(root,width=40,height=2,bg='pink')
  10. ent1.grid(row=0,column=1,padx=10,pady=5)
  11. ent2=Text(root,width=40,height=2,bg='pink').grid(row=100,column=1,padx=10,pady=5)
  12. #俺的纯真想法是输入一个数字通过giao!按钮将数字乘以2返回到第二个文本框{:10_266:}
复制代码

  1. >>> Exception in Tkinter callback
  2. Traceback (most recent call last):
  3.   File "C:\Users\ASUS\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1702, in __call__
  4.     return self.func(*args)
  5.   File "C:/Users/ASUS/Desktop/嗨.py", line 5, in A
  6.     ent2.insert(INSERT,c)
  7. AttributeError: 'NoneType' object has no attribute 'insert'
  8. Exception in Tkinter callback
  9. Traceback (most recent call last):
  10.   File "C:\Users\ASUS\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1702, in __call__
  11.     return self.func(*args)
  12.   File "C:/Users/ASUS/Desktop/嗨.py", line 5, in A
  13.     ent2.insert(INSERT,c)
  14. AttributeError: 'NoneType' object has no attribute 'insert'
复制代码

(报错内容)
为什莫第二个文本框不显示内容呀
如果我要让第二个文本框显示有什么好的解决办法吗?谢谢大佬们了
小小鱼币,不成敬意
最佳答案
2020-12-18 22:29:33
ent2=Text(root,width=40,height=2,bg='pink').grid(row=100,column=1,padx=10,pady=5)

这里还是分开吧
修改后如下

  1. from tkinter import *
  2. def A():
  3.     b=ent1.get(1.0,END)
  4.     c=int(b)*2
  5.     ent2.insert(INSERT,c)
  6. root=Tk()
  7. theButton=Button(root,text='giao!',command=A)
  8. theButton.grid(row=3,column=1,sticky=E,padx=10,pady=5)
  9. ent1=Text(root,width=40,height=2,bg='pink')
  10. ent1.grid(row=0,column=1,padx=10,pady=5)
  11. ent2=Text(root,width=40,height=2,bg='pink')
  12. ent2.grid(row=100,column=1,padx=10,pady=5)
  13. #ent2.pack()
  14. #俺的纯真想法是输入一个数字通过giao!按钮将数字乘以2返回到第二个文本框{:10_266:}
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-12-18 22:29:33 | 显示全部楼层    本楼为最佳答案   

回帖奖励 +3 鱼币

ent2=Text(root,width=40,height=2,bg='pink').grid(row=100,column=1,padx=10,pady=5)

这里还是分开吧
修改后如下

  1. from tkinter import *
  2. def A():
  3.     b=ent1.get(1.0,END)
  4.     c=int(b)*2
  5.     ent2.insert(INSERT,c)
  6. root=Tk()
  7. theButton=Button(root,text='giao!',command=A)
  8. theButton.grid(row=3,column=1,sticky=E,padx=10,pady=5)
  9. ent1=Text(root,width=40,height=2,bg='pink')
  10. ent1.grid(row=0,column=1,padx=10,pady=5)
  11. ent2=Text(root,width=40,height=2,bg='pink')
  12. ent2.grid(row=100,column=1,padx=10,pady=5)
  13. #ent2.pack()
  14. #俺的纯真想法是输入一个数字通过giao!按钮将数字乘以2返回到第二个文本框{:10_266:}
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-12-19 09:04:20 | 显示全部楼层
小甲鱼的铁粉 发表于 2020-12-18 22:29
这里还是分开吧
修改后如下

大佬牛,我能不能再问一下这样为什莫就可以了嘞
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-12-19 22:43:43 | 显示全部楼层
小伤口 发表于 2020-12-19 09:04
大佬牛,我能不能再问一下这样为什莫就可以了嘞
  1. ent2=Text(root,width=40,height=2,bg='pink')
复制代码

在这句代码之后ent2就变成了Text类型,但是如果直接下面这样
  1. ent2=Text(root,width=40,height=2,bg='pink').grid(row=100,column=1,padx=10,pady=5)
复制代码

经过Text的grid,ent2就没有了类型,成了noneType了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-12-20 09:58:48 | 显示全部楼层
小甲鱼的铁粉 发表于 2020-12-19 22:43
在这句代码之后ent2就变成了Text类型,但是如果直接下面这样

经过Text的grid,ent2就没有了类型,成 ...

哦哦哦,谢谢大佬
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-12-21 09:30:48 | 显示全部楼层

回帖奖励 +3 鱼币

都是大佬
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-12-21 10:34:59 | 显示全部楼层

回帖奖励 +3 鱼币

感谢分享!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-19 18:59

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表