_tkinter.TclError:无效的命令名称“ .36763856”是什么意思?

时间:2018-09-13 22:13:55

标签: python user-interface tkinter

我缩小了错误来源的位置,发现了:

SCREEN = "HELLO"
screen.configure(text="works?")  #this is where the error is coming from

不太确定错误是什么意思或我在做什么错,但最终我想将text="works?"更改为text=SCREEN

** 编辑 **

好..所以人们评论说我没有发布足够的代码。这是完整的代码:

import datetime as dt
from tkinter import *
import tkinter
import random

""" I know that there are two imports for tkinter, that is on purpose """


""" ON START """

on = True

top = tkinter.Tk()

top.configure(background="red")

Time = dt.time()
hour = 0

SCREEN = "Screen Unavailable"

def run():
    time = dt.time()
    checkTimeOut(time)
    #checkSign()
    checkButtons()
    SCREEN = "HELLO"
    screen.configure(text="works?")

def checkTimeOut(time): # finish later
    if time == 59:
        hour += 1


def restartNumCount():
    n1 = "n/a"
    n2 = "n/a"
    n3 = "n/a"
    n4 = "n/a"
    n5 = "n/a"
    n6 = "n/a"
    n7 = "n/a"
    n8 = "n/a"
    n9 = "n/a"

def checkCurrentNums(num):

    one = False
    two = False
    three = False
    four = False
    five = False
    six = False
    seven = False
    eight = False
    nine = False

    if n1 != "n/a":
        n1 = str(num)
        one = True
    elif n2 != "n/a":
        n2 = str(num)
        two = True
    elif n3 != "n/a":
        n3 = str(num)
        three = True
    elif n4 != "n/a":
        n4 = str(num)
        four = True
    elif n5 != "n/a":
        n5 = str(num)
        five = True
    elif n6 != "n/a":
        n6 = str(num)
        six = True
    elif n7 != "n/a":
        n7 = str(num)
        seven = True
    elif n8 != "n/a":
        n8 = str(num)
        eight = True
    elif n9 != "n/a":
        n9 = str(num)
        nine = True
    else:
        print("All full...")

""" Button 0 """

def bu00on0():
    bu00on = True
def bu00onOFF():
    bu00on = False

""" Button 1 """

def bu11on1():
    bu11on = True
def bu11onOFF():
    bu11on = False

""" Button 2 """

def bu22on2():
    bu22on = True
def bu22onOFF():
    bu22on = False

""" Button 3 """

def bu33on3():
    bu33on = True
def bu33onOFF():
    bu33on = False

""" Button 4 """

def bu44on4():
    bu44on = True
def bu44onOFF():
    bu44on = False

""" Button 5 """

def bu55on5():
    bu55on = True
def bu55onOFF():
    bu55on = False

""" Button 6 """

def bu66on6():
    bu66on = True
def bu66onOFF():
    bu66on = False

""" Button 7 """

def bu77on7():
    bu77on = True
def bu77onOFF():
    bu77on = False

""" Button 8 """

def bu88on8():
    bu88on = True
def bu88onOFF():
    bu88on = False

""" Button 9 """

def bu99on9():
    bu99on = True
def bu99onOFF():
    bu99on = False

def allToString():
    if one == True:
            nCHOOSE = n1
            if two == True:
                nCHOOSE = n1 + n2
                if three == True:
                    nCHOOSE = n1 + n2 + n3 
                    if four == True:
                        nCHOOSE = n1 + n2 + n3 + n4
                        if five == True:
                            nCHOOSE = n1 + n2 + n3 + n4 + n5
                            if six == True:
                                nCHOOSE = n1 + n2 + n3 + n4 + n5 + n6
                                if seven == True:
                                    nCHOOSE = n1 + n2 + n3 + n4 + n5 + n6 + n7
                                    if eight == True:
                                        nCHOOSE = n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8
                                        if nine == True:
                                            nCHOOSE = n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8 + n9

def popupmsg(msg):
    popup = tkinter.Tk()
    popup.wm_title("!")
    label = tkinter.Label(popup, text=msg)
    label.pack(side="top", fill="x", pady=10)
    B1 = tkinter.Button(popup, text="Okay", command = popup.destroy)
    B1.pack()
    popup.mainloop()

def command0():
    popupmsg("You pressed \'0\'")
def command1():
    popupmsg("You pressed \'1\'")
def command2():
    popupmsg("You pressed \'2\'")
def command3():
    popupmsg("You pressed \'3\'")
def command4():
    popupmsg("You pressed \'4\'")
def command5():
    popupmsg("You pressed \'5\'")
def command6():
    popupmsg("You pressed \'6\'")
def command7():
    popupmsg("You pressed \'7\'")
def command8():
    popupmsg("You pressed \'8\'")
def command9():
    popupmsg("You pressed \'9\'")

def commandPLUS():
    popupmsg("You pressed \'+\'")
def commandMINUS():
    popupmsg("You pressed \'-\'")
def commandMULTIPLY():
    popupmsg("You pressed \'x\'")
def commandDIVIDE():
    popupmsg("You pressed \'÷\'")
"""
def checkSign():
    if buppon:
        allToString()                       
        restartNumCount()
        buppon = False
    if buddon:
        allToString()
        restartNumCount()
        buddon = False
    if buxon:
        allToString()
        restartNumCount()
        buxxon = False
    if bumon:
        allToString()
        restartNumCount()
        bummon = False
"""
def checkButtons():
    if bu00on:
        checkCurrentNums(0)
    if bu11on:
        checkCurrentNums(1)
    if bu22on:
        checkCurrentNums(2)
    if bu33on:
        checkCurrentNums(3)
    if bu44on:
        checkCurrentNums(4)
    if bu55on:
        checkCurrentNums(5)
    if bu66on:
        checkCurrentNums(6)
    if bu77on:
        checkCurrentNums(7)
    if bu88on:
        checkCurrentNums(8)
    if bu99on:
        checkCurrentNums(9)

""" SCREEN LABEL THING """

screen = tkinter.Label(top, text=SCREEN, borderwidth=1 )
screen.grid(row=0,column=1)

""" END SCREEN LABEL THING """

""" NUMBER BUTTONS """

bu0on = tkinter.Button(top, text="0", fg="white", bg="black", command=command0).grid(row=4,column=1) 
bu1on = tkinter.Button(top, text="1", fg="white", bg="black", command=command1).grid(row=1,column=0) 
bu2on = tkinter.Button(top, text="2", fg="white", bg="black", command=command2).grid(row=1,column=1) 
bu3on = tkinter.Button(top, text="3", fg="white", bg="black", command=command3).grid(row=1,column=2) 
bu4on = tkinter.Button(top, text="4", fg="white", bg="black", command=command4).grid(row=2,column=0) 
bu5on = tkinter.Button(top, text="5", fg="white", bg="black", command=command5).grid(row=2,column=1) 
bu6on = tkinter.Button(top, text="6", fg="white", bg="black", command=command6).grid(row=2,column=2) 
bu7on = tkinter.Button(top, text="7", fg="white", bg="black", command=command7).grid(row=3,column=0) 
bu8on = tkinter.Button(top, text="8", fg="white", bg="black", command=command8).grid(row=3,column=1) 
bu9on = tkinter.Button(top, text="9", fg="white", bg="black", command=command9).grid(row=3,column=2) 

bu00on = False
bu11on = False
bu22on = False
bu33on = False
bu44on = False
bu55on = False
bu66on = False
bu77on = False
bu88on = False
bu99on = False

""" END OF NUMBER BUTTONS """

""" SIGN PRESSED FUNCTIONS """

def bupponp():
    buppon = True
def bupponpOFF():
    buppon = False

def bummonm():
    bummon = True
def bummonmOFF():
    bummon = False

def buddond():
    buddon = True
def buddondOFF():
    buddon = False

def buxxonx():
    buxxon = True
def buxxonxOFF():
    buxxon = False

""" END OF SIGN PRESSED FUNCTIONS """

""" SIGN BUTTONS """

buppon = False
bummon = False
buxxon = False
buddon = False

bupon = tkinter.Button(top, text="+", fg="white", bg="black", command=commandPLUS).grid(row=1,column=4)
bumon = tkinter.Button(top, text="-", fg="white", bg="black", command=commandMINUS).grid(row=2,column=4)
buxon = tkinter.Button(top, text="x", fg="white", bg="black", command=commandMULTIPLY).grid(row=3,column=4)
budon = tkinter.Button(top, text="÷", fg="white", bg="black", command=commandDIVIDE).grid(row=4,column=4)

""" END OF SIGN BUTTONS """

Bon = tkinter.Button(top, text="ON", fg="red", command=quit) 

n1 = "n/a"
n2 = "n/a"
n3 = "n/a"
n4 = "n/a"
n5 = "n/a"
n6 = "n/a"
n7 = "n/a"
n8 = "n/a"
n9 = "n/a"

equation = ""
choose = ""
nCHOOSE = ""







""" NOTHING BELOW HERE EXCEPT THE RUN METHOD AND MAINLOOP """
top.mainloop()
while True: 
    run()

1 个答案:

答案 0 :(得分:1)

  

_tkinter.TclError:无效的命令名称“ .36763856”是什么意思?

这意味着您正试图在已被破坏的窗口小部件上调用方法。