Exception in tkinter callback как исправить

Here is my code:

#Game Restart Func 

def restart_program():
    for widget in root.winfo_children():
        widget.destroy()

    button = Button(root, text='Stop', width=25, command=root.destroy)
    button.pack()

    b1 = Button(root, text="Restart", command=restart_program)
    b1.pack()

    g = GalagaGame(root)
    root.after(10, g.gameLoop())
    root.mainloop()

This function is a function to restart the game
And the main function was written like this

root = Tk()

button = Button(root, text='Stop', width=25, command=root.destroy)
button.pack()

b1 = Button(root, text="Restart", command=restart_program)
b1.pack()

g = GalagaGame(root)
root.after(10, g.gameLoop())
root.mainloop()

But there are still strange errors.

Exception in Tkinter callback

Traceback (most recent call last):
  File "C:UsersKim DongukAppDataLocalProgramsPythonPython36-32libtkinter__init__.py", line 1699, in __call__
    return self.func(*args)

  File "C:UsersKim DongukAppDataLocalProgramsPythonPython36-32libtkinter__init__.py", line 745, in callit
    func(*args)

  File "C:UsersKim DongukDesktopGame projectgame_sourcegame.py", line 281, in gameLoop
    self.paint(self.canvas)

  File "C:UsersKim DongukDesktopGame projectgame_sourcegame.py", line 260, in paint
    self.canvas.delete(ALL)

  File "C:UsersKim DongukAppDataLocalProgramsPythonPython36-32libtkinter__init__.py", line 2508, in delete
    self.tk.call((self._w, 'delete') + args)

_tkinter.TclError: invalid command name ".!canvas"

How can I fix this error?

from tkinter import *
from functools import partial
from tkinter.messagebox import *
import re




 

#текст
a="Авторизируйтесь" #Зоглоловок окна
b="Вход в приложение"#Текст в приложениии
c="Пожайлуста введите данные:"#Текст в приложение 2
d="Вы зарагистрированны?"#Вопрос о регистрации пользовотеля
e="Придумайте надежный логин и пароль"
f="Регистрация"


#Логины
namelist = ["ilia"]
#Пароли
passwdlist= ["2" "1"]

window = Tk()
window.title(a)


text1=Label(text=b)
text1.pack(fill=BOTH, expand=True)

text2=Label(text=c)
text2.pack(fill=BOTH, side=LEFT, expand=True)

entryLOGIN = Entry()
entryLOGIN.insert(0,"Логин")
entryLOGIN.pack(fill=BOTH, side=LEFT, expand=True)


entryPASS = Entry()
entryPASS.pack(fill=BOTH, side=LEFT, expand=True)
entryPASS.insert(0,"Пароль")


i=0


#Оценка стойкости пароля
def ChekDATA(entryEPASS,entryELOGIN,namelist,passwdlist):
  passw=entryEPASS.get()
  name=entryELOGIN.get()
  fl=0
  a=0
  while True:
    if (len(passw)<8):
      fl=-1
      break
    elif not re.search("[a-z]",passw):
      fl=-1
      break
    elif not re.search ("[A-Z]",passw):
      fl=-1                   
      break   
    elif not re.search("[0-9]",passw):
      fl=-1   
      break   
    elif re.search("s",passw):
      fl=-1
      break
  if fl==0:
    passwdlist.append(passw)
    a=a+1
  while True:
    if (len(name)<8):

      fl=-1
      break
    elif not re.search("[a-z]",name):
      fl=-1
      break
    elif not re.search ("[A-Z]",name):
      fl=-1                   
      break   
    elif not re.search("[0-9]",name):
      fl=-1   
      break   
    elif re.search("s",name):
      fl=-1
      break
  if fl==0:
    namelist.append(name)
    a=a+1
  if a==2:
    avt(passwdlist,namelist,a,b,c,d,e,f,window)
  else:
    showinfo("Информация","Пароль ненадежн повторите попытку")
    reg(window)   



#Приложение регистрации
def reg(window):
  window.destroy()
  Regw= Tk()
  Regw.title(f)

  text1E=Label(text=e)
  text1E.pack(fill=BOTH, expand=True)

  text2E=Label(text=c)
  text2E.pack(fill=BOTH, side=LEFT, expand=True)

  entryELOGIN = Entry()
  entryELOGIN.insert(0,"Логин")
  entryELOGIN.pack(fill=BOTH, side=LEFT, expand=True)


  entryEPASS = Entry()
  entryEPASS.pack(fill=BOTH, side=LEFT, expand=True)
  entryEPASS.insert(0,"Пароль")

  buttonREG = Button(text="Ввести",command=partial
  (
  ChekDATA,
  entryPASS,
  entryLOGIN,
  namelist,
  passwdlist
  ))
  buttonREG.pack(fill=BOTH, side=BOTTOM, expand=True)
 

def avt(passwdlist,namelist,a,b,c,d,e,f,window):   
  #Приложение авторизации
  window.destroy()
  window = Tk()
  window.title(a)


  text1=Label(text=b)
  text1.pack(fill=BOTH, expand=True)

  text2=Label(text=c)
  text2.pack(fill=BOTH, side=LEFT, expand=True)

  entryLOGIN = Entry()
  entryLOGIN.insert(0,"Логин")
  entryLOGIN.pack(fill=BOTH, side=LEFT, expand=True)


  entryPASS = Entry()
  entryPASS.pack(fill=BOTH, side=LEFT, expand=True)
  entryPASS.insert(0,"Пароль")


  i=0
  #Функция авторизации и проверки паролей на подлинность
  def increase(namelist,passwdlist,entryLOGIN,entryPASS,i):
    p=entryPASS.get()
    name=entryLOGIN.get()
    
    while i<10:
      if name in namelist:
        print("имя есть")
        if p in passwdlist:
          print(a)
          window.destroy()
          main(name)
        else:
          
          entryPASS.delete(0,END)
          i=+1
      else :
        showerror(
      "Ошибка","Введен неверный логин"
      )   
        enrtyLOGIN.delete(0,END)
        i=+1
    else:
      showerror(
      "Ошибка","Попытки кончились"
      )
      


  buttonVXOD = Button(
        master=window,
        text="Войти",
        command=partial(increase,
        namelist,
        passwdlist,
        entryLOGIN,
        entryPASS,
        i
      )
    )
  buttonVXOD.pack(fill=BOTH, side=BOTTOM, expand=True)





  #Вопрос о том зарегистрирован ли пользователь
def check():
  answer = askyesno(
  title="Вопрос",
  message=d
  )
  if answer:
    avt(passwdlist,namelist,a,b,c,d,e,f,window)
  else:
    reg(window)
      
    
check()









window.mainloop()

Exception in Tkinter callback
Traceback (most recent call last):
File “C:UsersDanilAppDataLocalProgramsPythonPython38libtkinter__init
__.py”, line 1892, in __call__
return self.func(*args)
File “tt.py”, line 12, in btn_click
messagebox.showinfo(title= ‘Название’, message=info_str)
NameError: name ‘messagebox’ is not defined

from tkinter import*


root = Tk()


def btn_click():
	login = loginInput.get()
	password = passField.get()

	info_str = f'Данные : {str(login)}, {str (password)}'
	messagebox.showinfo(title= 'Название', message=info_str)


	# ошибка
	# messagebox.showerror(title='', message='!!!Ошибка!!!' )


	
root['bg'] = '#fafafa'
root.title ('Название программы')
root.wm_attributes('-alpha', 1)
root.geometry('700x600') 
root.iconbitmap('C:/Users/Danil/Desktop/armchair-icon.ico')

root.resizable(width=True , height=True)

canvas = Canvas(root, height=700, width=600)
canvas.pack()


frame = Frame(root, bg='green')
frame.place(relx=0.15, rely=0.15, relwidth=0.7 , relheight=0.7 )


titel = Label(frame, text='Logerpod', bg='gray', font=40)
titel.pack()
btn= Button(frame, text='Кнопка', bg= 'blue' , command =btn_click )
btn.pack()



loginInput = Entry(frame, bg= 'white')
loginInput.pack()


passField = Entry(frame, bg= 'white', show='*')
passField.pack()



root.mainloop()

выбивает ошибку :
“Exception in Tkinter callback
Traceback (most recent call last):
File ”C:Python27liblib-tkTkinter.py“, line 1410, in __call__
return self.func(*args)
File ”D:Институтпитон прогаosnovav2_5.py“, line 35, in tenvtwo
txt_val = float(text1.get())
TypeError: get() takes at least 2 arguments (1 given)

ну и где мне взять второй аргумент.

 # -*- coding: cp1251 -*-
# -*- coding: UTF-8 -*-
from Tkinter import *
from sys import*
def exit():
    """Выход из проги""" 
    root.destroy()    
def solver(text1):
    
   if x1 >= 0:
       x1= bin(text1)
       text = "this nuber is: %s n x1"%(text1, x1)
       return text
def solver(txt_val1):
    if x1>=0:
        x1=oct(txt_val1)
        text = "this nuber is: %s n x1"%(txt_val1, x1)
        return text
    
def inserter(value):
    """ Функция вставки информации """
    output.delete("0.0","end")
    output.insert("0.0",value)
def clear(event):
    """ Очищает поле """
    caller = event.widget
    caller.delete("0", "end")
def tenvtwo():
   
    try:
        txt_val = float(text1.get())
        inserter(solver(txt_val))
    except ValueError:
        inserter("nevernoe chislo")
def tenveight():
    try:
        txt_val1=int(text1.get())
        inserter(solver(txt_val1))
    except ValueError:
        inserter("nevernoe chislo")
def tenvsixteen():
    inserter("lol3")
def twovten():
   inserter("lol4")
    
def sixteenvten():
    inserter("lol5")
    
def twovsixteen():
    inserter("lol6")
    
def sixteenvtwo():
   inserter("lol7")
root = Tk()
root.title(u"Калькулятор систем счисления")
root.geometry('400x300')
lab = Label(root, height=1, width=10, text=u"Ввод данных")
lab.place(x=45,y=20)
lab1 = Label(root, height=1, width=10, text=u"Результат")
lab1.place(x=45,y=230)
text1=Text(root,height=1,width=10,font='Arial 14',wrap=WORD)
text1.bind("<FocusIn>", clear)
text1.place(x=45,y=50)
but2 = Button(root, bg="yellow", text=u"Выход", command=exit)
but2.place(x=350,y=250)
but3 = Button(root, bg="green", text=u"10 в 2", command = tenvtwo)
but3.place(x=45,y=90)
but4 = Button(root, bg="green", text=u"10 в 8", command = tenveight)
but4.place(x=100,y=90)
but5 = Button(root, bg="green", text=u"10 в 16", command = tenvsixteen)
but5.place(x=170,y=90)
but6 = Button(root, bg="green", text=u"2 в 10", command=twovten)
but6.place(x=240,y=90)
but7 = Button(root, bg="green", text=u"16 в 10", command=sixteenvten)
but7.place(x=45,y=120)
but8 = Button(root, bg="green", text=u"2 в 16", command=twovsixteen)
but8.place(x=100,y=120)
but9 = Button(root, bg="green", text=u"16 в 2", command=sixteenvtwo)
but9.place(x=170,y=120)
output = Text(root, font="Arial 14", height=1, width=10)
output.bind("<FocusIn>", clear)
output.place(x=48,y=250)
mainloop()

Отредактировано artez (Сен. 16, 2017 14:30:38)

Exception in Tkinter callback
Traceback (most recent call last):
File “C:UsersClaireAppDataRoamingPythonPython36site-packagespandascoreindexesbase.py”, line 2898, in get_loc
return self._engine.get_loc(casted_key)
File “pandas_libsindex.pyx”, line 70, in pandas._libs.index.IndexEngine.get_loc
File “pandas_libsindex.pyx”, line 101, in pandas._libs.index.IndexEngine.get_loc
File “pandas_libshashtable_class_helper.pxi”, line 1675, in pandas._libs.hashtable.PyObjectHashTable.get_item
File “pandas_libshashtable_class_helper.pxi”, line 1683, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: ‘Id’

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “C:Program FilesPython36libtkinter_init_.py”, line 1702, in call
return self.func(*args)
File “C:UsersClaireDesktopNew folder (6)login-verification-masterrun.py”, line 161, in login_submit
TrackImages(a)
File “C:UsersClaireDesktopNew folder (6)login-verification-masterrun.py”, line 135, in TrackImages
aa=df.loc[df[‘Id’] == Id][‘Name’].values
File “C:UsersClaireAppDataRoamingPythonPython36site-packagespandascoreframe.py”, line 2906, in getitem
indexer = self.columns.get_loc(key)
File “C:UsersClaireAppDataRoamingPythonPython36site-packagespandascoreindexesbase.py”, line 2900, in get_loc
raise KeyError(key) from err
KeyError: ‘Id’

please help me with this one too.

Добавить комментарий