【发布时间】:2020-04-25 15:59:00
【问题描述】:
我在运行此代码 sn-p 时遇到上述错误。我试图通过在用户输入不在数据框中的值时创建错误窗口来防止用户输入错误。我正在运行的代码如下
import tkinter as tk
import tkinter.messagebox
import pandas as pd
root= tk.TK()
def customer_search():
try:
search = int(entry1.get())
except ValueError:
tk.messagebox("that customer doesnt exist, please enter a new number") #error proofing has to be added tomorrow
search = int(entry1.get())
k = df.loc[df['UniqueID'] == search]
k.to_excel("dashboard.xlsx")
df.to_excel("check.xlsx")
canvas1 = tk.Canvas(root, width=400, height=300)
canvas1.pack()
entry1 = tk.Entry(root)
canvas1.create_window(200, 140, window=entry1)
button1 = tk.Button(text='Enter a customer for analysis', command=customer_search)
button1.pack()
我得到的错误如下
Exception in Tkinter callback
Traceback (most recent call last):
File "C:/Users/....py", line 42, in customer_search
search = int(entry1.get())
ValueError: invalid literal for int() with base 10: 'a'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users...\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:/Users....py", line 44, in customer_search
tk.messagebox("that customer doesnt exist, please enter a new number") #error proofing has to be added tomorrow
TypeError: 'module' object is not callable
Process finished with exit code 0
【问题讨论】:
-
它是一个模块......也许你需要使用
tk.messagebox.showinfo()等等。 -
你确定这是你得到的错误吗?在收到其他错误之前,您应该收到错误
module 'tkinter' has no attribute TK。 -
jizhihaoSAMA 已修复,谢谢!
标签: python pandas tkinter error-handling