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 ::----::

can you get any help from your teacher?

can you get any help from your teacher?

You already know that answer, we're in the same class.
---------

Heres a more current code version, comes with window pre-sized and some command attributes for the file menu (only close, at this time)

#
#
# File: gui_GameScreen_Code_v0.4.pyw
# Programmer: A. Smith
# Created: 20100305

# Edited: 2010031_
# Time: 13:56


# ::Goals:: - Divide windows (top, center, right) for alignment of buttons/controls
# - Include a timer or timer zone for adding with Game Code
# - Bind Menu buttons (Close:Done. Rest:Incomplete) to Event to do its prescripted action

# ::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.
    # Divide window into panes for aspect ratio
# .timerZone() Not complete, ignore until GUI more complete/add in programming phase.
# 
#


## ::----:: End Programmer Comments ::----::



## ::----:: Start Code ::----::
## ::----:: Import Libraries ::----::


## Import all from Tkinter to begin GUI
from Tkinter import *
# import time ## For timer ?
import Tkinter as tk
#import Tkinter.ttk as ttK

## ::----:: End Import ::----::
## ::----:: GUI Game Screen ::----::


## Creating GUI in one class (section)
class Application(Frame):


    ## ::--:: Create Widget Containers ::--::

    def __init__(self, master=None):

        Frame.__init__(self, master)
        
        ## ::--:: Window Attributes ::--::
        
        self.grid(sticky=N+S+E+W)
       # self.windowDivide() ## Incomplete - see notes.
       # self.gameWindow() ## Incomplete - see notes.

       
       ## ::--:: Menu Bar Icons ::--::
       
        self.fileDrop()
        self.helpDrop()
        self.viewDrop() ## contains simple, immediate screen changes ?
        

        ## ::--:: Game/Control Buttons/Items ::--::

        #self.timerZone() ## Incomeplete - see notes.
        self.startButton()
        self.resetButton()
        self.pauseButton()
        self.stopButton()



    ## ::----:: Widget code/screen structure ::----::
    ## This is where the widgets are coded/placed

        
    ## ::----:: Menu Code ::----::
            
    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_command(label="Close", command=self.quit)


    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 windowDivide(self):

      # m1 = PanedWindow():
       # m1.pack(fill=BOTH, expand=1)

       # top = Label(m1, text="top pane")

       

   # def gameWindow(self):

     #   self.gameWin = Toplevel(self, relief=FLAT)
     #   self.gameWin.grid(ipadx=6, ipady=6, 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)


    ## ::----:: Button Events ::----::
    ## ::--:: Controls ::--::

    #def (self, event):
        #if self.["background"] == "":
        #    self.["background"] = "red"
        #else:
        #    self.()

    ## ::----:: End Events ::----::

## ::----:: End GUI Screen ::----::    
## ::----:: GUI Run Script ::----::

## This prepares the program and runs it

## Sizes the tK window
root = tk.Tk()
root.geometry("1000x800+140+90")

app = Application()
app.master.title("Major Project - SDD. V.03")  ## This appears in the title bar
app.mainloop()

## ::----:: End Run Script ::----::
## ::----:: End Program ::----::

Thanks to the numerous help threads upon this forum. I have been able to almost achieve several goals in the code.

Currently, I am having trouble centering a new child window in the main window. I think the problem might be created by the drop down menu being in the main window. And then the control buttons also being in the main window (Located to the far right of the screen).

Im thinking that creating the menu in the main window, placing the buttons in a new child window that is positioned to the right of screen and this new child window (titled gameScreen) should then center itself.

How does that line of thinking seem?

(Btw, Even though I havent' had the replies to this thread. Everyone has been most helpful in previous topics. Thank you all)

Ive re-organised my code into this version. It cleans it up and incorporates all the updates and new addions from the previous versions.

It fixes:
- placing a child window inside the main Tk window.
The screen has three windows inside the main window. The Menu, Game Controls and Game Screen (Still represented by a button).
- Complex code from messy debugging

It creates (so far):
- Unaligned windows, unresponsive buttons to aligning themselves.

The is also a small (failed) attempt at including several 'instant' window sizes from the view menu. I wasn't able to get this working after several hours and have decided to put it off until the window problems are fixed. Help is still greatly appreciated.

#
# File: gui_GameScreen_Code_v0.6.pyw
# Programmer: A. Smith
# Created: 20100305

# Edited: 20100319
# Time: 09:31



# ::Goals::
# - Fix child windows for mainMenu, controlButtons and gameScreen. So they can be
# positioned and aligned.
# - Align buttons within each window.
# - Algin windows


# ::Notes::
# - Libraries : Excludes Error possiblity if file is used in Py3.x instead of Py2.x
#



## ::----:: End Programmer Comments ::----::


## ::----:: Start All Code ::----::
## ::----:: Import Libraries ::----::

try:
    # Python2.x
    from Tkinter import *
except ImportError:
    # Python3.x
    import tkinter as tk

## ::----:: End Import ::----::

## ::----:: GUI Window Main Code::----::



## ::----:: Main Tk Window Class ::----::
class mainMenu(Frame):

    def __init__(self, master=None):

        Frame.__init__(self, master)
        
        self.grid(sticky='nw',row=0, column=0)

    ## ::--:: Drop Menu Icons ::--::
        
        self.fileDrop()
        self.helpDrop()
        self.viewDrop()

    ## ::--:: End Menu Icons ::--::
        
## ::----:: Drop down Menu Code ::----::
    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_command(label="Close", command=self.quit)


    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.size_normVar = IntVar()
        self.size_oneVar = IntVar()
        self.size_twoVar = IntVar()
        self.size_threeVar = IntVar()
        self.mb.menu.add_checkbutton(label="Colours", variable=self.presetColourVar)
        self.mb.menu.add_checkbutton(label="Grid Lines", variable=self.gridlinesVar)
        self.mb.menu.add_checkbutton(label="Size Norm ", variable=self.size_normVar)
        self.mb.menu.add_checkbutton(label="Size 1 ", variable=self.size_oneVar)
        self.mb.menu.add_checkbutton(label="Size 2 ", variable=self.size_twoVar)
        self.mb.menu.add_checkbutton(label="Size 3 ", variable=self.size_threeVar)

        #return size_oneVar

       # if size_oneVar == self.root.geometry('1000x800+140+90'):
      #      self.root.geomtry('800x800+140+90')
       # elif size_twoVar == self.root.geometry('1000x800+140+90'):
       #     self.root.geometry('1280x768+140+90')
       # elif size_threeVar == self.root.geometry('1000x800+140+90'):
       #     self.root.geometry('1024x768+140+90')
       # else:
        #    self.root.geometry('1000x800+140+90')
## ::----:: End Menu Code ::----::
            
## ::----:: End Main Tk Window Class ::----::


            
## ::----:: Control Buttons Class ::----::
class controlButtons(Frame):

    def __init__(self, master=None):

        Frame.__init__(self, master)

        self.grid(sticky='ne', row=5, column=6)

    ## ::--:: Control Items ::--::

        #self.timerZone() ## Incomeplete - see notes.
        self.startButton()
        self.resetButton()
        self.pauseButton()
        self.stopButton()

    ## ::--:: End Control Buttons/Items ::--::

## ::----:: Control Buttons ::----::
    def startButton(self):

        top=self.winfo_toplevel()
        top.rowconfigure(0, weight=1)
        top.columnconfigure(0, weight=1)
        self.rowconfigure(2, weight=1)
        self.columnconfigure(10, weight=1)
        self.start = Button(self, text="Start", relief=RAISED, font=("Arial", 10))
        self.start.grid(row=2, column=0, sticky=N+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=0, 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=6, column=0, 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=8, column=0, sticky=S+E)

## ::----:: End Control Buttons ::----::

## ::----:: End Control Buttons Class ::----::



## ::----:: Game Screen Class ::----::
class gameScreen(Frame):

    def __init__(self, master=None):

        Frame.__init__(self, master)

        self.grid()

        self.testButton()

    ## ::--:: Test Button ::--::

    def testButton(self):

        top=self.winfo_toplevel()
        top.rowconfigure(0, weight=1)
        top.columnconfigure(0, weight=1)
        self.rowconfigure(5, weight=1)
        self.columnconfigure(5, weight=1)
        self.tB = Button(self, text="Test Button - Game Screen", relief=RAISED, font=("Arial", 10))
        self.tB.grid(sticky=N+E)

    ## ::--:: End Test Button ::--::

## ::----:: End Game Screen Class ::----::



## ::----:: Parent Tk Window ::----::
class mainTkWindow():

    #def __init__(self):

    #    self.root = Tk()
    #    self.root.title('Major Project - SDD. v0.6')
    #    self.root.geometry('1000x800+140+90')
       
    def menu_Icons(self):
        mainMenu()
       
              
    def gameControl(self):
        controlButtons()
        
    def gameView(self):
        gameScreen()
        
## ::----:: End Parent Tk Window ::----::
## ::----:: Run Program ::----::

root = Tk()
root.title('Major Project - SDD. v0.6')
root.geometry('1000x800+140+90')

mw = mainTkWindow()
mw.menu_Icons()
mw.gameControl()
mw.gameView()


## ::----:: End Run Program ::----::
## ::----:: End GUI Window Main Code::----::

If anyone could point me in the right direction to aligning these windows and widgets. It would be greatly appreciated. Or just other help/tips.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.