1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
attack-on-blocks/GUI.py

59 lines
1.8 KiB
Python
Raw Normal View History

2015-04-21 11:00:31 +01:00
from tkinter import *
from tkinter.ttk import *
import logging
2015-04-22 09:52:09 +01:00
import game
PADDING_TITLE = 15
PADDING_BUTTON = 9
2015-04-21 11:00:31 +01:00
2015-04-22 09:52:09 +01:00
PROGRAM_OPEN = True
class Main_Window:
2015-04-21 11:00:31 +01:00
def __init__(self, master):
self.master = master
self.master.title("SPACE INVADERS")
2015-04-22 09:52:09 +01:00
self.title = Label(self.master)
self.title.config(text="SPACE INVADERS!",font=("Courier New", 37))
self.title.pack(side="top", padx=PADDING_BUTTON, pady=PADDING_TITLE/2)
self.start_button = Button(self.master, style="Menu.TButton")
self.start_button.config(text="Play Game")
self.start_button.pack(fill=BOTH, ipadx=PADDING_BUTTON/2, ipady=PADDING_BUTTON/2, padx=PADDING_BUTTON, pady=PADDING_BUTTON)
self.start_button.bind('<Button-1>', self.play_game)
2015-04-21 11:00:31 +01:00
2015-04-22 09:52:09 +01:00
self.exit_button = Button(self.master, style="Quit.TButton")
self.exit_button.config(text="Quit Game")
self.exit_button.pack(ipadx=PADDING_BUTTON/3, ipady=PADDING_BUTTON, padx=PADDING_BUTTON, pady=PADDING_BUTTON)
self.exit_button.bind('<Button-1>', self.close)
2015-04-21 11:00:31 +01:00
2015-05-06 09:50:48 +01:00
Style().configure("Menu.TButton", font=("Lucida", 25))
2015-04-22 09:52:09 +01:00
Style().configure("Quit.TButton", font=("Lucida", 15))
2015-04-21 11:00:31 +01:00
logging.info("GUI Generated.")
2015-04-22 09:52:09 +01:00
def play_game(self, event):
logging.info("Game Started.")
self.master.withdraw()
2015-05-06 09:50:48 +01:00
exit_code = game.initialise(self.master, None)
if exit_code == "player collision":
self.title["text"] = "You Lost, Try Again?"
2015-04-22 09:52:09 +01:00
def close(self, event):
logging.critical("Closing Main Window.")
self.master.destroy()
def display():
2015-04-21 11:00:31 +01:00
root=Tk()
root.resizable(width=False, height=False)
2015-04-22 09:52:09 +01:00
front_end=Main_Window(root)
2015-04-21 11:00:31 +01:00
root.mainloop()
2015-04-22 09:52:09 +01:00
logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.DEBUG)
2015-04-21 11:00:31 +01:00
if __name__ == "__main__":
2015-04-22 09:52:09 +01:00
display()