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

57 lines
1.7 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-04-22 09:52:09 +01:00
Style().configure("Menu.TButton", font=("Lucida", 25 ))
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()
game.initialise(self.master, None)
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()