I am working on a Simon game using python and tkinter, just now it is incomplete, but I don't know if I am doing it right because it looks messy, and I would like to have a check on my code for corrections and suggestions on how to improve it.
This is the first game I'm making, and I don't have to much experience in programming.
This is my actual entire code:
from Tkinter import *
import Tkinter
import random
base = Tkinter.Tk()
fr = Tkinter.Frame(base, bg="black", width="238", height="250")
score = Tkinter.Label(base, bg="black", fg="white", text="Score:")
score.place(x = 30, y = 15)
s = 0
scoreNum = Tkinter.Label(base, bg="black", fg="white", text = s)
scoreNum.place(x = 70, y = 15)
best = Tkinter.Label(base, bg="black", fg="white", text="Best:")
best.place(x = 155, y = 15)
b = 0
bestNum = Tkinter.Label(base, bg="black", fg="white", text = b)
bestNum.place(x = 188, y = 15)
clicks = []
color = 0
def yellowClick():
yellow.configure(activebackground="yellow3")
yellow.after(500, lambda: yellow.configure(activebackground="yellow"))
global clicks
global color
color = 1
clicks.append(color)
yellow = Tkinter.Button(base, bd="0", highlightthickness="0",
width="7", height="5", activebackground="yellow",
bg="yellow3", command = yellowClick)
yellow.place(x = 30, y = 50)
def blueClick():
blue.configure(activebackground="medium blue")
blue.after(500, lambda: blue.configure(activebackground="blue"))
global clicks
global color
color = 2
clicks.append(color)
blue = Tkinter.Button(base, bd="0", highlightthickness="0",
width="7", height="5", activebackground="blue",
bg="medium blue", command = blueClick)
blue.place(x = 125, y = 50)
def redClick():
red.configure(activebackground="red3")
red.after(500, lambda: red.configure(activebackground="red"))
global clicks
global color
color = 3
clicks.append(color)
red = Tkinter.Button(base, bd="0", highlightthickness="0",
width="7", height="5", activebackground="red",
bg = "red3", command = redClick)
red.place(x = 30, y = 145)
def greenClick():
green.configure(activebackground="dark green")
green.after(500, lambda: green.configure(activebackground="green4"))
global clicks
global color
color = 4
clicks.append(color)
green = Tkinter.Button(base, bd="0", highlightthickness="0",
width="7", height="5", activebackground="green4",
bg="dark green", command = greenClick)
green.place(x = 125, y = 145)
def scoreUp():
global s
s = s + 1
scoreNum.configure(text = s)
r = random.randint(1, 4)
sequence = []
def checkSequence():
global clicks
global sequence
if clicks == sequence:
scoreUp()
def showSequence():
global r
global sequence
if r == 1:
yellow.configure(bg="yellow")
yellow.after(1000, lambda: yellow.configure(bg="yellow3"))
sequence.append(r)
base.after(5000, checkSequence)
elif r == 2:
blue.configure(bg="blue")
blue.after(1000, lambda: blue.configure(bg="medium blue"))
sequence.append(r)
base.after(5000, checkSequence)
elif r == 3:
red.configure(bg="red")
red.after(1000, lambda: red.configure(bg="red3"))
sequence.append(r)
base.after(5000, checkSequence)
elif r == 4:
green.configure(bg="green4")
green.after(1000, lambda: green.configure(bg="dark green"))
sequence.append(r)
base.after(5000, checkSequence)
base.after(2000, showSequence)
fr.pack()
base.resizable(False, False)
base.mainloop()
Actually I'm checking the sequence with time because I can't find another to do it.