I'm using Tkinter as the GUI for my Software Design and Development Major Project, This is only to be a 'screen' shot of what the final GUI interface might look like, however. I have been having quite a hard time with Tk. My reference manual is from New Mexico Tech (www.nmt.edu/tcc).
So far I have a drop down menu with the tearoff option, and the basic buttons. But Im currently trying to:
- Adjust the screen to start at a permanent size
- Divide the screen into 3 sections (Located Top, Right and Center)
Top will have the Dropdown menu, Right the control buttons and Center will house the actual game.
- Include a timing option (Much, much , much later)
- Create the center game screen, as a child (?).
I would like help, but mainly to be pointed towards tools/reference manuals that can help me learn.
#
# File: gui_GameScreen_Code_v0.3.pyw
# Programmer: A. Smith
# Created: 20100305
# Edited: 20100309
# Time: 12:36
# Notes:
# .windowDivide() and gameWindow() are 2 attempts at the same goal. incomplete.
# divide into Top (menu), Right (controls) and Center (game screen)
# Center screen needs to be a child (?), but has to say in main. Not be seperate.
# .timerZone() Not complete, ignore until GUI more complete/add in programming phase.
#
#
## ::----:: End Programmer Comments ::----::
## ::----:: Start Code ::----::
## ::----:: GUI Game Screen ::----::
## Import all from Tkinter to begin GUI
from Tkinter import *
# import time ## For timer ?
import Tkinter as tk
## Creating GUI in one class (section)
class Application(Frame):
## This creates the container for each widget/section
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid(sticky=N+S+E+W)
# self.windowDivide() ## Divide window into panes for aspect ratio
self.fileDrop()
self.helpDrop()
self.viewDrop() ## contains simple, immediate screen changes ?
#self.gameWindow() ## Needs code. Incomplete. Create window in main app. seperate buttons and game graphics
#self.timerZone() ## Needs code. Incomplete. need count up timer
## (Idea) Just place output time window. As timer code is needed in programming of game, not Tk screen
self.startButton()
self.resetButton()
self.pauseButton()
self.stopButton()
## ::----:: Widget code/screen structure ::----::
## This is where the widgets are coded/placed
## ::----:: Menu Code ::----::
#def windowDivide(self):
# m1 = PanedWindow():
# m1.pack(fill=BOTH, expand=1)
# top = Label(m1, text="top pane")
def fileDrop(self):
self.mb = Menubutton(self, text="File", relief=RIDGE, font=("Arial", 10))
self.mb.grid(row=0, column=0)
self.mb.menu = Menu(self.mb, tearoff=1)
self.mb["menu"] = self.mb.menu
self.optionVar = IntVar()
self.closeVar = IntVar()
self.mb.menu.add_checkbutton(label="Options", variable=self.optionVar)
self.mb.menu.add_checkbutton(label="Close", variable=self.closeVar)
def helpDrop(self):
self.mb = Menubutton(self, text="Help", relief=RIDGE, font=("Arial", 10))
self.mb.grid(row=0, column=1)
self.mb.menu = Menu(self.mb, tearoff=1)
self.mb["menu"] = self.mb.menu
self.helpFileVar = IntVar()
self.helpWikiVar = IntVar()
self.creditVar = IntVar()
self.mb.menu.add_checkbutton(label="Help File", variable=self.helpFileVar)
self.mb.menu.add_checkbutton(label="Help Wiki", variable=self.helpWikiVar)
self.mb.menu.add_checkbutton(label="Credits", variable=self.helpWikiVar)
def viewDrop(self):
self.mb = Menubutton(self, text="View", relief=RIDGE, font=("Arial", 10))
self.mb.grid(row=0, column=2)
self.mb.menu = Menu(self.mb, tearoff=1)
self.mb["menu"] = self.mb.menu
self.presetColourVar = IntVar()
self.gridlinesVar = IntVar()
self.mb.menu.add_checkbutton(label="Colours", variable=self.presetColourVar)
self.mb.menu.add_checkbutton(label="Grid Lines", variable=self.gridlinesVar)
## ::----:: End Menu Code ::----::
## ::----:: Game Window Code ::----::
#def gameWindow(self):
# self.gameWin = Toplevel(self, relief=FLAT)
# self.gameWin.grid(row=1, column=0, sticky=CENTER)
## ::----:: End Game Window Code ::----::
## ::----:: Button Code ::----::
#def timerZone(self):
# curtime = ''
# clock = Tkinter.Label()
# clock.grid(row=6, column=5)
# def tick():
# global curtime
# newtime - time.strfttime('%H:%M:%S')
# if newtime != curtime:
# curtime = newtime
# clock.config(text=curtime)
# clock.after(200, tick)
# tick()
def startButton(self):
top=self.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(2, weight=1)
self.columnconfigure(5, weight=1)
self.start = Button(self, text="Start", relief=RAISED, font=("Arial", 10))
self.start.grid(row=3, column=10, sticky=E)
def resetButton(self):
top=self.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(4, weight=1)
self.columnconfigure(10, weight=1)
self.reset = Button(self, text="Reset", relief=RAISED, font=("Arial", 10))
self.reset.grid(row=4, column=10, sticky=E)
def pauseButton(self):
top=self.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(6, weight=1)
self.columnconfigure(10, weight=1)
self.pause = Button(self, text="Pause", relief=RAISED, font=("Arial", 10))
self.pause.grid(row=5, column=10, sticky=E)
def stopButton(self):
top=self.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(8, weight=1)
self.columnconfigure(10, weight=1)
self.stop = Button(self, text="Stop", relief=RAISED, font=("Arial", 10))
self.stop.grid(row=6, column=10, sticky=E)
## ::----:: End GUI Screen ::----::
## ::----:: GUI Run Script ::----::
## This prepares the program and runs it
app = Application()
app.master.title("Major Project - SDD. V.03") ## This appears in the title bar
app.mainloop()
## ::----:: End Program ::----::