Traceback (most recent call last):
File "C:\Users\User\Desktop\game 1.9.1.py", line 76, in <module>
but_1 = Button(text='1', width=3, height=1, bg='blue', font='Hack 30', command=click_button, true = 1)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 2679, in __init__
Widget.__init__(self, master, 'button', cnf, kw)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 2601, in __init__
self.tk.call(
_tkinter.TclError: unknown option "-true"
I planned to make 1 correct button, and that it would change. When you click on the correct button, the score is added to 1, and if it is incorrect, the score is reset The game code itself:
from tkinter import *
import random as rn
import time
rn.seed()
timer = TIME = 5
root = Tk()
root.title('game')
root.geometry('720x1280')
true = 0
clicks = 0
def click_button():
global clicks, timer, true
clicks += 1
timer = TIME
labelClick['text'] = str(clicks)
labelClick.pack() #Variable clicks
count = rn.randrange(1,10,1)
print(count)
count = str(count) #randomizer of the correct button
if count == '1':
bgcolor='blue'
if count == '2':
bgcolor='green'
if count == '3':
bgcolor='red'
if count == '4':
bgcolor='yellow'
if count == '5':
bgcolor='orange'
if count == '6':
bgcolor='brown'
if count == '7':
bgcolor='violet'
if count == '8':
bgcolor='grey'
if count == '9':
bgcolor='pink'
#bgcolor='blue' #random numbers and colors
but_0 = Button(text=count, width=3, height=1, bg= bgcolor, font='Hack 30', command=click_button)
print(bgcolor)
but_0.place(x=310, y=140)
but_0['state'] = 'disabled'
counter = 1000
def countdown():
global timer, counter
global clicks
print(timer)
timer -= 1
counter -= 5
if timer <= 0:
clicks -= clicks
timer = 5
root.after(counter, countdown)
but_10 = Button(text=timer, width=3, height=1, font='Hack 30', command=click_button)
print(timer)
but_10.place(x=310, y=40)
but_10['state'] = 'disabled' #A button with the right button
labelClick = Label(root, text=clicks)
labelClick.pack()
but_1 = Button(text='1', width=3, height=1, bg='blue', font='Hack 30', command=click_button, true = 1)
but_2 = Button(text='2', width=3, height=1, bg='green', font='Hack 30', command=click_button, true = 2)
but_3 = Button(text='3', width=3, height=1, bg='red', font='Hack 30', command=click_button, true = 3)
but_4 = Button(text='4', width=3, height=1, bg='yellow', font='Hack 30', command=click_button, true = 4)
but_5 = Button(text='5', width=3, height=1, bg='orange', font='Hack 30', command=click_button, true = 5)
but_6 = Button(text='6', width=3, height=1, bg='brown', font='Hack 30', command=click_button, true = 6)
but_7 = Button(text='7', width=3, height=1, bg='violet', font='Hack 30', command=click_button, true = 7)
but_8 = Button(text='8', width=3, height=1, bg='grey', font='Hack 30', command=click_button, true = 8)
but_9 = Button(text='9', width=3, height=1, bg='pink', font='Hack 30', command=click_button, true = 9) #Buttons
if true == count:
clicks += 1
else:
clicks = 0
but_1.place(x=210, y=240)
but_2.place(x=310, y=240)
but_3.place(x=410, y=240)
but_4.place(x=210, y=340)
but_5.place(x=310, y=340)
but_6.place(x=410, y=340)
but_7.place(x=210, y=440)
but_8.place(x=310, y=440)
but_9.place(x=410, y=440) #button layout
root.after(1, countdown)
root.mainloop()
true
parameter that you added is unexpected. \$\endgroup\$