Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tkinter窗口配置python错误“;“一无所获”;_Python_Window_Themes_Tkinter - Fatal编程技术网

Tkinter窗口配置python错误“;“一无所获”;

Tkinter窗口配置python错误“;“一无所获”;,python,window,themes,tkinter,Python,Window,Themes,Tkinter,好的,我有一个很长的计划。我对主题有问题。我所说的主题是指,当在Tkinter中激活时,我构建了一个特定的函数来更改背景和文本颜色。 以下是代码的简化版本: global theme theme = 0 windows = [] buttons = [] labels = [] messageboxes = [] 代码。。。 更多代码。。。(我在本节中定义了其他口味) 甚至更多的代码 好的,终于完成了。 现在,当我运行这个时,主题变换器工作了。直到我使用“windowinator”。

好的,我有一个很长的计划。我对主题有问题。我所说的主题是指,当在Tkinter中激活时,我构建了一个特定的函数来更改背景和文本颜色。 以下是代码的简化版本:

 global theme
 theme = 0
 windows = []
 buttons = []
 labels = []
messageboxes = []
代码。。。 更多代码。。。(我在本节中定义了其他口味) 甚至更多的代码 好的,终于完成了。 现在,当我运行这个时,主题变换器工作了。直到我使用“windowinator”。只要我以前打开的窗口没有关闭,主题就可以毫无问题地更改。但当我只关闭其中一个并试图改变“主题”时:我得到一个普通的(无主题的窗口)和一个尴尬的错误:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
    return self.func(*args)
  File "C:\Users\Ahmet\Desktop\Fobby\FOBBY.py", line 70, in flavor_3
    w.config(bg = 'black')
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1202, in configure
    return self._configure('configure', cnf, kw)
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1193, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
TclError: invalid command name "."

有谁能告诉我到底出了什么问题吗?

您应该只创建
Tk
类的一个实例。看起来正在发生的事情是初始默认窗口(“.”)正在被破坏。Tkinter不是设计用来这样使用的


如果您想要多个窗口,请创建
Toplevel

的实例。您的某些缩进不正确。现在我遇到另一个错误:Tkinter回调中出现异常。。。TclError:无效的命令名“.44532640”@madprogramer:这意味着您正试图在某个已销毁的小部件上运行命令。好的,那么是否有命令来检查小部件何时已销毁并执行功能?
def set_theme():
    global theme
    global register
    if theme == 0:
        flavor_0()
    elif theme == 1:
        flavor_1()
    elif theme == 2:
        flavor_2()
    elif theme == 3:
        flavor_3()
    elif theme == 4:
        flavor_4()
    thememenu = Tkinter.Menu(menubar,tearoff = 0)
    thememenu.add_command(label="Plain",command = flavor_0)
    thememenu.add_command(label="Mint", command = flavor_1)
    thememenu.add_command(label="Strawberry", command = flavor_2)
    thememenu.add_command(label="Banana", command = flavor_3)
    thememenu.add_command(label="Peanut", command = flavor_4)
    menubar.add_cascade(label="Flavor", menu = thememenu)

    def windowinator():
        new = Tkinter.Tk()
        windows.append(new)
        set_theme()

    windowinator = Tkinter.Button(root,text="New Window", command = windowinator)
    windowinator.pack()
    buttons.append(windowinator)
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
    return self.func(*args)
  File "C:\Users\Ahmet\Desktop\Fobby\FOBBY.py", line 70, in flavor_3
    w.config(bg = 'black')
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1202, in configure
    return self._configure('configure', cnf, kw)
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1193, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
TclError: invalid command name "."