Skip to main content
Formatting
Source Link
DMGregory
  • 141k
  • 23
  • 258
  • 401

Traceback (most recent call last): File "C:\Users\User\Desktop\game 1.9.1.py", line 76, in 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"

 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"

Traceback (most recent call last): File "C:\Users\User\Desktop\game 1.9.1.py", line 76, in 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"

 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"
added 834 characters in body; edited title
Source Link

How to make a timer, Error when creating random numbers and a record for playing pythonbuttons

How to make a timerTraceback (the initial time is 5 secondsmost recent call last): File "C:\Users\User\Desktop\game 1.9.1.py", when it reaches zeroline 76, the score is resetin but_1 = Button(text='1', except for the recordwidth=3, and when you press the right buttonheight=1, the time is restoredbg='blue', font='Hack 30', command=click_button, true = 1) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\tkinter_init_.py", random numbersline 2679, in init Widget.init(when you press the right buttonself, the time is restored and adds 1 point to the scoremaster, as well as'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 the record ifmake 1 correct button, and that it is beatenwould change. And if the score is reset incorrectly) record forWhen you click on the game (whencorrect button, the score is greater than the recordadded to 1, it (record) overwritten and saved after exiting the game) a link to the site (there will be an icon in the corner if you click on it is incorrect, the site will open) and how to make this game available for Android(.apk) in python? Thescore 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()

How to make a timer, random numbers and a record for playing python

How to make a timer (the initial time is 5 seconds, when it reaches zero, the score is reset, except for the record, and when you press the right button, the time is restored), random numbers (when you press the right button, the time is restored and adds 1 point to the score, as well as to the record if it is beaten. And if the score is reset incorrectly) record for the game (when the score is greater than the record, it (record) overwritten and saved after exiting the game) a link to the site (there will be an icon in the corner if you click on it, the site will open) and how to make this game available for Android(.apk) in python? The game code itself:

from tkinter import *
import random as rn
root = Tk()
root.title('game')
root.geometry('720x1280')

clicks = 0
def click_button():
    global clicks
    clicks += 1
    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' #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)
but_2 = Button(text='2', width=3, height=1, bg='green', font='Hack 30', command=click_button)
but_3 = Button(text='3', width=3, height=1, bg='red', font='Hack 30', command=click_button)
but_4 = Button(text='4', width=3, height=1, bg='yellow', font='Hack 30', command=click_button)
but_5 = Button(text='5', width=3, height=1, bg='orange', font='Hack 30', command=click_button)
but_6 = Button(text='6', width=3, height=1, bg='brown', font='Hack 30', command=click_button)
but_7 = Button(text='7', width=3, height=1, bg='violet', font='Hack 30', command=click_button)
but_8 = Button(text='8', width=3, height=1, bg='grey', font='Hack 30', command=click_button)
but_9 = Button(text='9', width=3, height=1, bg='pink', font='Hack 30', command=click_button) #Buttons


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.mainloop()

Error when creating random buttons

Traceback (most recent call last): File "C:\Users\User\Desktop\game 1.9.1.py", line 76, in 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()
added 134 characters in body
Source Link
from tkinter import *
import random as rn
root = Tk()
root.title('game')
root.geometry('720x1280')

clicks = 0
def click_button():
    global clicks
    clicks += 1
    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' #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)
but_2 = Button(text='2', width=3, height=1, bg='green', font='Hack 30', command=click_button)
but_3 = Button(text='3', width=3, height=1, bg='red', font='Hack 30', command=click_button)
but_4 = Button(text='4', width=3, height=1, bg='yellow', font='Hack 30', command=click_button)
but_5 = Button(text='5', width=3, height=1, bg='orange', font='Hack 30', command=click_button)
but_6 = Button(text='6', width=3, height=1, bg='brown', font='Hack 30', command=click_button)
but_7 = Button(text='7', width=3, height=1, bg='violet', font='Hack 30', command=click_button)
but_8 = Button(text='8', width=3, height=1, bg='grey', font='Hack 30', command=click_button)
but_9 = Button(text='9', width=3, height=1, bg='pink', font='Hack 30', command=click_button) #Buttons


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.mainloop()
from tkinter import *
import random as rn
root = Tk()
root.title('game')
root.geometry('720x1280')

clicks = 0
def click_button():
    global clicks
    clicks += 1
    labelClick['text'] = str(clicks)
    labelClick.pack()

    count = rn.randrange(1,10,1)
    print(count)
    count = str(count)

    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'



    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'


labelClick = Label(root, text=clicks)
labelClick.pack()



but_1 = Button(text='1', width=3, height=1, bg='blue', font='Hack 30', command=click_button)
but_2 = Button(text='2', width=3, height=1, bg='green', font='Hack 30', command=click_button)
but_3 = Button(text='3', width=3, height=1, bg='red', font='Hack 30', command=click_button)
but_4 = Button(text='4', width=3, height=1, bg='yellow', font='Hack 30', command=click_button)
but_5 = Button(text='5', width=3, height=1, bg='orange', font='Hack 30', command=click_button)
but_6 = Button(text='6', width=3, height=1, bg='brown', font='Hack 30', command=click_button)
but_7 = Button(text='7', width=3, height=1, bg='violet', font='Hack 30', command=click_button)
but_8 = Button(text='8', width=3, height=1, bg='grey', font='Hack 30', command=click_button)
but_9 = Button(text='9', width=3, height=1, bg='pink', font='Hack 30', command=click_button)


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)


root.mainloop()
from tkinter import *
import random as rn
root = Tk()
root.title('game')
root.geometry('720x1280')

clicks = 0
def click_button():
    global clicks
    clicks += 1
    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' #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)
but_2 = Button(text='2', width=3, height=1, bg='green', font='Hack 30', command=click_button)
but_3 = Button(text='3', width=3, height=1, bg='red', font='Hack 30', command=click_button)
but_4 = Button(text='4', width=3, height=1, bg='yellow', font='Hack 30', command=click_button)
but_5 = Button(text='5', width=3, height=1, bg='orange', font='Hack 30', command=click_button)
but_6 = Button(text='6', width=3, height=1, bg='brown', font='Hack 30', command=click_button)
but_7 = Button(text='7', width=3, height=1, bg='violet', font='Hack 30', command=click_button)
but_8 = Button(text='8', width=3, height=1, bg='grey', font='Hack 30', command=click_button)
but_9 = Button(text='9', width=3, height=1, bg='pink', font='Hack 30', command=click_button) #Buttons


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.mainloop()
removing 'game-mechanics' & 'support' as question is not asking about either (as described by the guidance for said tags)
Link
Pikalek
  • 13.4k
  • 5
  • 49
  • 54
Loading
Source Link
Loading