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

85 lines
2.7 KiB
Python
Raw Normal View History

2015-04-21 11:00:31 +01:00
from tkinter import *
from tkinter.ttk import *
2015-05-07 19:38:43 +01:00
import tkMessageBox
2015-04-21 11:00:31 +01:00
import logging
2015-04-22 09:52:09 +01:00
import game
2015-05-07 19:38:43 +01:00
2015-04-22 09:52:09 +01:00
PADDING_TITLE = 15
PADDING_BUTTON = 9
2015-04-21 11:00:31 +01:00
2015-04-22 09:52:09 +01:00
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-05-07 19:38:43 +01:00
self.start_button = Button(self.master, style="Menu.TButton")
self.start_button.config(text="Show Options")
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.show_options)
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)
2015-05-07 19:38:43 +01:00
if exit_code != "QUIT": tkMessageBox.showinfo("You Lose!", exit_messages[code])
def show_options(self, event):
self.new_window = Toplevel(self.master)
self.app = Options_Window(self.new_window)
2015-04-22 09:52:09 +01:00
def close(self, event):
logging.critical("Closing Main Window.")
self.master.destroy()
2015-05-07 19:38:43 +01:00
class Options_Window:
def __init__(self, master):
self.master = master
self.master.title("SPACE INVADERS - Options")
self.title = Label(self.master)
self.title.config(text="OPTIONS",font=("Courier New", 37))
self.title.pack(side="top", padx=PADDING_BUTTON, pady=PADDING_TITLE/2)
def close(self):
self.master.destroy()
2015-04-22 09:52:09 +01:00
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
2015-05-07 19:38:43 +01:00
exit_messages = {
"LIVES":"You ran out of lives!",
"PLAYER COLLISION":"The enemies got to you!"
}
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()