Python Forum
[Tkinter] .get() doesn't exist?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] .get() doesn't exist?
#1
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:
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.1

Thanks in advance!
Reply


Messages In This Thread
.get() doesn't exist? - by GalaxyCoyote - Oct-13-2019, 02:32 PM
RE: .get() doesn't exist? - by Axel_Erfurt - Oct-13-2019, 03:52 PM
RE: .get() doesn't exist? - by GalaxyCoyote - Oct-13-2019, 05:03 PM
RE: .get() doesn't exist? - by Axel_Erfurt - Oct-13-2019, 05:14 PM
RE: .get() doesn't exist? - by GalaxyCoyote - Oct-13-2019, 05:30 PM
RE: .get() doesn't exist? - by joe_momma - Oct-13-2019, 10:11 PM
RE: .get() doesn't exist? - by GalaxyCoyote - Oct-14-2019, 03:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] _tkinter.TclError: image "pyimage2" doesn't exist Killdoz 1 10,678 May-30-2020, 09:48 AM
Last Post: menator01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020