未填充的“self”参数

2024-09-29 02:27:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Tkinter来编写一个游戏,我需要一个按钮(按钮a)主要是关闭的,而不是当一个不同的按钮(按钮B)被按下时按钮a打开这里是我迄今为止尝试的

def click():   # defines the press of Button B
    p1name = P1.get()
    p2name = P2.get()
    namethanks = 'thank you "' + p1name + ' " you are player 1 (X) \n and thank you "' + p2name +'" you are player 2 (O)'
    namesubmission.insert(END, namethanks)
    realgametime.configure(state=DISABLED,)

这就是代码定义按钮A

realgametime(window, text="play the game", width=13, command=play, bg=bgcolour, fg=fgcolour, state=DISABLED) .grid(row=4, column=1, sticky=W)  # button A

那么这就是错误:

enter image description here

请帮忙


Tags: theyouplaygettkinter按钮arestate
1条回答
网友
1楼 · 发布于 2024-09-29 02:27:02

据我所知,你曾经

realgametime(window, text="play the game", width=13, command=play, bg=bgcolour, fg=fgcolour, state=DISABLED) .grid(row=4, column=1, sticky=W)  # button A

创建按钮,但未将其分配给任何变量

调用realgametime.configure时,是在类本身上调用方法,而不是在实例化的按钮上调用方法

试着这样做:

buttonA = realgametime(window, text="play the game", width=13, command=play, bg=bgcolour, fg=fgcolour, state=DISABLED) .grid(row=4, column=1, sticky=W)
buttonA.configure(state=DISABLED)

相关问题 更多 >