Oct-13-2019, 02:32 PM
I am trying to make a game that displays a word with a colour and the user has to type the colour into the box instead of the word.
But there is an issue, .get() doesn't work. I get an error saying that Tkinter has no attribute .get(), I am extremely new to Tkinter (actually this is my first program on it).
Here is the code:
Thanks in advance!
But there is an issue, .get() doesn't work. I get an error saying that Tkinter has no attribute .get(), I am extremely new to Tkinter (actually this is my first program on it).
Here is the code:
import tkinter
from tkinter import *
import random
Pinput = 0 #var
Loop = True #this is for the game loop
Tcolour = str #Text colour
Ttext = str #Words
points = 0 #counts points
def submit():
Pinput = Box.get()
print(Pinput)
if Pinput == Tcolour:
points = points + 1
window = Tk() #screen setup
window.title("Colour game recreation")
window.geometry("500x300")
window.configure(background = "black")
window.resizable(0,0) #makes the window unscaleable
Box = Entry(window) .grid(row = 2, column = 3) #text entry setup
Button(window, text = "SUBMIT", command = submit) .grid(row = 3, column = 3) #Submit button
Label(window, text = points, bg = "black", fg = "white", font = "none 15 bold") .grid(row = 5, column = 3) #score
while Loop:
Ttext = random.randint(1,9) #setting up text
if Ttext == 1:
Ttext = "Red"
elif Ttext == 2:
Ttext = "Blue"
elif Ttext == 3:
Ttext = "Green"
elif Ttext == 4:
Ttext = "Orange"
elif Ttext == 5:
Ttext = "Yellow"
elif Ttext == 6:
Ttext = "Purple"
elif Ttext == 7:
Ttext = "Brown"
elif Ttext == 8:
Ttext = "Black"
elif Ttext == 9:
Ttext = "White"
Tcolour = random.randint(1,9) #setting up colours
if Tcolour == 1:
Tcolour = "Red"
elif Tcolour == 2:
Tcolour = "Blue"
elif Tcolour == 3:
Tcolour = "Green"
elif Tcolour == 4:
Tcolour = "Orange"
elif Tcolour == 5:
Tcolour = "Yellow"
elif Tcolour == 6:
Tcolour = "Purple"
elif Tcolour == 7:
Tcolour = "Brown"
elif Tcolour == 8:
Tcolour = "Black"
elif Tcolour == 9:
Tcolour = "White"
Label(window, text = Ttext, bg = "black", fg = Tcolour, font = "none 30 bold") .grid(row = 1, column = 3) #word display
window.mainloop()Python Version: 3.6.1Thanks in advance!
