【发布时间】:2019-08-30 04:35:34
【问题描述】:
我正在尝试在 python 3.7 中学习 tkinter gui,我有这个代码:
from tkinter import *
# Configuración de la ventana principal
root=Tk()
root.title("Cath Config")
#Definición de clases
#Frames
class marco(Frame):
def __init__(self, master=None, color="#F3F3F3", ancho="1024", alto="680", borde="5", tipoborde="groove"):
Frame.__init__(self)
self.master=master
self.config(bg=color,width=ancho,height=alto,bd=borde,relief=tipoborde)
self.pack()
#Configuración del widget frame
mainframe1=marco(master="root")
#Ejecución de la ventana principal
root.mainloop()
问题是代码“有效”,当我运行该代码时,它显示带有主框架的根没有问题,但是当我尝试关闭根时,它没有关闭并抛出此错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\konoe\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Users\konoe\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 2061, in destroy
for c in list(self.children.values()): c.destroy()
File "C:\Users\konoe\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 2306, in destroy
if self._name in self.master.children:
AttributeError: 'str' object has no attribute 'children'
【问题讨论】:
-
试试
Frame.__init__(self, master)?