import pygame, sys
from tkinter import *

def runfile(runfilename):
  with open(runfilename,"r") as rnf:
    exec(rnf.read())

def text(text,fontStyle,fontSize,color,coord,surface):
  font = pygame.font.SysFont(fontStyle,fontSize)
  text = font.render(text,True,color)
  surface.blit(text,coord)

def button(Surface, color,Rect,width):
  pygame.draw.rect(Surface, color,Rect,width)

def findHighscore():
  infile = open("highscore.txt","r")
  mylist = []
  for line in infile:
    a = line.strip()
    mylist.append(a)
  return max(mylist)


pygame.init()
red = [255,0,0]
while True:
  mousepos = pygame.mouse.get_pos() #checking mouse position
  mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
  highscore = pygame.display.set_mode((300, 150))
  #highscore.fill([213, 219, 219])
  pygame.display.set_caption("Highscore")

  text('Highest Score: ' + str(findHighscore()),"comicsansms", 30,[0, 0, 200],(10,20),highscore)

  button(highscore,[0,0,0], [90,70,120,26], 0)
  text('Main Menu',"times", 25,red,(90,70),highscore)
  if (90 <= mousepos[0] <= 90+120 and 70 <= mousepos[1] <= 70+27 ):
      if mouseclick[0] == 1:
          runfile('Snake_Game.py')

  button(highscore,[0,0,0], [125,105,45,27], 0)
  text('Quit',"times", 25,red,(125,105),highscore)
  if (125 <= mousepos[0] <= 125+45 and 105 <= mousepos[1] <= 105+27 ):
        if mouseclick[0] == 1:
          pygame.quit()
          sys.exit()
          
  pygame.display.update()

##MyButton1 = Button(highscore, text="BUTTON1")
##MyButton1.grid(row=0, column=0)