python “发生异常:TclError未知选项”

3hvapo4f  于 2022-11-27  发布在  Python
关注(0)|答案(1)|浏览(346)

我正在pyhton上进行内存匹配,但一直收到此错误:
“发生异常:TclError unknown option”这是代码,有什么想法吗?

import random
import time
from tkinter import *
from PIL import Image, ImageTk
from turtle import *

def show_symbol(x, y):
    global first
    global previousX, previousY
    buttons[x, y]["text"] = button_symbols[x, y]
    buttons[x, y].update_idletasks()

    if first:
        previousX = x
        previousY = y
        first = False
    elif previousX != x or previousY != y:
        if buttons[previousX, previousY]["text"] != buttons[x, y]["text"]:
            time.sleep(0.5)
            buttons[previousX, previousY]["text"] = ""
            buttons[x, y]["text"] = ""
        else:
            buttons[previousX, previousY]["command"] = DISABLED
            buttons[x, y]["command"] = DISABLED
        first = True

root = Tk()
root.title('Memory Match')
root.resizable(width=False, height=False)

buttons = {}
first = True
previousX = 0
previousY = 0

royaljello = PhotoImage(Image.open(r"D:\Documents\Projects\Memorysnap\StarEgg.gif"))
treat = PhotoImage(Image.open(r"D:\Documents\Projects\Memorysnap\treat.gif"))
star_treat = PhotoImage(Image.open(r"D:\Documents\Projects\Memorysnap\star_treat.gif"))
strawberry = PhotoImage(Image.open(r"D:\Documents\Projects\Memorysnap\Strawberry.gif"))
blueberry = PhotoImage(Image.open(r"D:\Documents\Projects\Memorysnap\Blueberry.gif"))
pineapple = PhotoImage(Image.open(r"D:\Documents\Projects\Memorysnap\Pineapple.gif"))
seed = PhotoImage(Image.open(r"D:\Documents\Projects\Memorysnap\seed.gif"))
star_jelly = PhotoImage(Image.open(r"D:\Documents\Projects\Memorysnap\StarJelly.gif"))
silveregg = PhotoImage(Image.open(r"D:\Documents\Projects\Memorysnap\Silver_Egg.gif"))
goldegg = PhotoImage(Image.open(r"D:\Documents\Projects\Memorysnap\Gold_Egg.gif"))
deemondegg = PhotoImage(Image.open(r"D:\Documents\Projects\Memorysnap\Diamond_Egg.gif"))
mythegg = PhotoImage(Image.open(r"D:\Documents\Projects\Memorysnap\Mythic_Egg.gif"))

button_symbols = {}
symbols = [royaljello, royaljello, treat, treat, star_treat, star_treat,
           strawberry, strawberry, blueberry, blueberry, pineapple, pineapple,
           seed, seed, star_jelly, star_jelly, silveregg, silveregg,
           goldegg, goldegg, deemondegg, deemondegg, mythegg, mythegg ]

random.shuffle(symbols)

for x in range(6) :
    for y in range(4) :
        button = Button(command=lambda x=x, y=y: show_symbol(x, y), window_height=3 window_width=3)     
        button.grid(column=x, row=y)
        button[x, y] = button
        button_symbols[x, y] = symbols.pop()

root.mainloop()
# Credit to Onett for images

这是语法(假设第61行在第60行的末尾)。提前谢谢你,我为我犯的任何amatuer错误道歉。

File "C:\Users\Martin\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 2601, in __init__
    self.tk.call(
_tkinter.TclError: unknown option "-window_height"
PS D:\Documents\Projects>
bqf10yzr

bqf10yzr1#

您的行:

button = Button(command=lambda x=x, y=y: show_symbol(x, y), window_height=3 window_width=3)

存在多个相关问题;正如错误消息所示,window_heightwindow_width选项对于小部件来说是未知的。您分别是指heightwidth吗?

相关问题