0

Hi guys,

Im trying to bring up a new window then the Credits button located in the help menu is clicked.

Im trying to run it as a command. So right now, that code doesnt work unless you comment out the creditsCommand region.

So can anyone point me in the right direction to get a new window displayed with text?

#
# File: gui_secondGen_v0.02.pyw
# Programmer: A. Smith
# Created: 20100323

# Edited: 20100504
# Time: 10:01

# Notes:
# 1) Working way down page. Class menu, screen, controls.
#


## ::----:: 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 Main Code::----::

   
class controlMenu(Frame):

    def __init__(self, master=None):
        Frame.__init__(self, master, bg='yellow')

        self.grid(row=0, column=0)

    ## ::--:: Define Menu ::--::

        self.fileMenu()
        self.viewMenu()
        self.helpMenu()

    ## ::--:: End Define Menu ::--::

## ::----:: Menu Code ::----::

    def fileMenu(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 viewMenu(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)

    def helpMenu(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", command=self.creditsCommand)  ##variable=self.helpWikiVar)

class creditsCommand():
        creditWin = Tk()
        creditWin.title("Credit Page")
        creditWin.geometry('600x400')
        self.creditWords(sticky='nswe')
        self.creditVar = IntVar()
        self.creditWords = Button(text="This is the credits page", font=("Arial", 10))
 


  #  def creditsCommand(self):
  #      creditWin = Tk()
  #      creditWin.title("Credit Page")
  #      creditWin.geometry('600x400')
  #      #self.creditVar = IntVar()
  #      creditWin.cWords = Button(text="This is the credits page", font=("Arial", 10))
 
## ::----:: End Menu Code ::----::

## ::----:: Parent Tk Window ::----::

class Program_Window():

    def __init__(self):
        
        self.root = Tk()
        self.root.title('Major Project - SDD. secondGen_v0.01')
        self.root.geometry('1000x600+140+90')
        
    def menu_Control(self):
        controlMenu()


    # def (self):
    # def (self):
    # def (self):

        
## ::----:: End Parent Tk Window ::----::
## ::----:: Run Program ::----::
        


mw = Program_Window()
mw.menu_Control()

## ::----:: End Run Program ::----::
## ::----:: End GUI Window Code::----::
2
Contributors
4
Replies
7
Views
6 Years
Discussion Span
Last Post by Alq Veers
1

You mean like this:

#
# File: gui_secondGen_v0.02.pyw
# Programmer: A. Smith
# Created: 20100323

# Edited: 20100504
# Time: 10:01

# Notes:
# 1) Working way down page. Class menu, screen, controls.
#

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

   
class controlMenu(Frame):

    def __init__(self, master=None):
        Frame.__init__(self, master, bg='yellow')

        self.grid(row=0, column=0)

        ## ::--:: Define Menu ::--::
        self.fileMenu()
        self.viewMenu()
        self.helpMenu()

## ::----:: Menu Code ::----::
    def fileMenu(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 viewMenu(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)

    def helpMenu(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", command=self.creditsCommand)  ##variable=self.helpWikiVar)

##class creditsCommand(self):
##        creditWin = Tk()
##        creditWin.title("Credit Page")
##        creditWin.geometry('600x400')
##        self.creditWords(sticky='nswe')
##        self.creditVar = IntVar()
##        self.creditWords = Button(text="This is the credits page", font=("Arial", 10))

    def creditsCommand(self):
        creditWin=Tk()
        creditWin.title("Credit Page")
        creditWin.geometry('600x400')
        #self.creditVar = IntVar()
        Button(creditWin,text="This is the credits page", font=("Arial", 10)).pack()
        creditWin.wait_window()

## ::----:: Parent Tk Window ::----::
class Program_Window():
    def __init__(self):
        self.root = Tk()
        self.root.title('Major Project - SDD. secondGen_v0.01')
        self.root.geometry('1000x600+140+90')
        print 'initialized'
        
    def menu_Control(self):
        controlMenu()
        self.root.mainloop()        
       
mw = Program_Window()
mw.menu_Control()
0

Yes, exactly that. Thank you tonyjv.

Im sure you've noticed Im still quite a novice at this, so thank you greatly for that.

:EDIT:

Would there be a way to make the words appear directly on the new window instead of on a button?

And with the self.root.mainloop() is that needed at the end of each function in the Parent Tk Window class?

Edited by Alq Veers: n/a

1

Change the Button to Label, if you do not want user to push it for something and use fill and expand:

Label(creditWin,text="This is the credits page", font=("Arial", 10)).pack(fill='both', expand='yes')

No you can be only in one mainloop, which waits and process user input.

0

Im also trying to put an embedded window into that screen, so it takes up most of the middle. Hopefully I can then use it to load images into it later and move an icon through the image via some control icons on the right hand-side of the screen.

Would you be able to point me to some reference material for something like this?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.