鱼C论坛

 找回密码
 立即注册
查看: 3236|回复: 4

[已解决]关于tkinter的,莫名错误

[复制链接]
发表于 2020-1-1 12:15:56 | 显示全部楼层 |阅读模式

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

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

x
  1. Exception in Tkinter callback
  2. Traceback (most recent call last):
  3.   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 1705, in __call__
  4.     return self.func(*args)
  5.   File "C:\Users\Administrator\Desktop\数据库\1.2.py", line 189, in <lambda>
  6.     editmenu.add_command(label="创建", command=lambda:new(self.win, conn))
  7.   File "C:\Users\Administrator\Desktop\数据库\1.2.py", line 102, in new
  8.     ttk.Button(newtp, text='确定', command = newtp.destroy())
  9.   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\tkinter\ttk.py", line 614, in __init__
  10.     Widget.__init__(self, master, "ttk::button", kw)
  11.   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\tkinter\ttk.py", line 559, in __init__
  12.     tkinter.Widget.__init__(self, master, widgetname, kw=kw)
  13.   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 2299, in __init__
  14.     (widgetName, self._w) + extra + self._options(cnf))
  15. _tkinter.TclError: bad window path name ".!toplevel"
复制代码


这是什么原因啊
最佳答案
2020-1-1 13:49:22
应该这样:

  1. #新建成绩
  2. def new(conn):
  3.     newtp = Toplevel()
  4.     newtp.geometry('300x500+200+200')
  5.     Label(newtp, text='学号:').pack()
  6.     sto = ttk.Entry(newtp)
  7.     sto.pack()
  8.     Label(newtp, text='学科号:').pack()
  9.     sc = ttk.Entry(newtp)
  10.     sc.pack()
  11.     Label(newtp, text='分数:').pack()
  12.     gr = ttk.Entry(newtp)
  13.     gr.pack()
  14.    
  15.     cursor = conn.cursor()
  16.     cursor.execute("""
  17.     use stsc
  18.     INSERT INTO score VALUES ('777','377','772')
  19.     """ )
  20.     conn.commit()
  21.     ttk.Button(newtp, text='确定', command = newtp.destroy)
  22.     newtp.mainloop()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-1-1 12:21:56 | 显示全部楼层
把代码发上来。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-1-1 13:48:47 | 显示全部楼层
zltzlt 发表于 2020-1-1 12:21
把代码发上来。
  1. #新建成绩
  2. def new(conn):
  3.     newtp = Toplevel()
  4.     newtp.geometry('300x500+200+200')
  5.     Label(newtp, text='学号:').pack()
  6.     sto = ttk.Entry(newtp)
  7.     sto.pack()
  8.     Label(newtp, text='学科号:').pack()
  9.     sc = ttk.Entry(newtp)
  10.     sc.pack()
  11.     Label(newtp, text='分数:').pack()
  12.     gr = ttk.Entry(newtp)
  13.     gr.pack()
  14.    
  15.     cursor = conn.cursor()
  16.     cursor.execute("""
  17.     use stsc
  18.     INSERT INTO score VALUES ('777','377','772')
  19.     """ )
  20.     conn.commit()
  21.     ttk.Button(newtp, text='确定', command = newtp.destroy())
  22.     newtp.mainloop
复制代码

  这是截取错的这一部分小代码   我是做一个数据库学生管理系统  
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-1-1 13:49:22 | 显示全部楼层    本楼为最佳答案   
应该这样:

  1. #新建成绩
  2. def new(conn):
  3.     newtp = Toplevel()
  4.     newtp.geometry('300x500+200+200')
  5.     Label(newtp, text='学号:').pack()
  6.     sto = ttk.Entry(newtp)
  7.     sto.pack()
  8.     Label(newtp, text='学科号:').pack()
  9.     sc = ttk.Entry(newtp)
  10.     sc.pack()
  11.     Label(newtp, text='分数:').pack()
  12.     gr = ttk.Entry(newtp)
  13.     gr.pack()
  14.    
  15.     cursor = conn.cursor()
  16.     cursor.execute("""
  17.     use stsc
  18.     INSERT INTO score VALUES ('777','377','772')
  19.     """ )
  20.     conn.commit()
  21.     ttk.Button(newtp, text='确定', command = newtp.destroy)
  22.     newtp.mainloop()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-1-1 13:54:59 | 显示全部楼层

哇原来这么简单   谢谢啦
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-26 08:08

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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