I have no idea how to create a Gui from another Gui using python. What I have so far is simply a basic Gui which you select one of the options from a dropdown menu and create another Gui. Here's what I have so far...

import sys
from tkinter import *

#def m

forces = []

def mCalculate():
    mtext = mass.get()
    mtext2 = acceleration.get()
    mlabel = Label(mGui,text = mtext * mtext2).pack()

def mGraph():
    messagebox.showinfo(title="Graphs",message="Graph option 1")

def secondGui Tk():
    secondGui.title('Second Gui')
    button = Button(text = 'Graph these points', command = mGraph).pack()

def mGraphAction():
    mPoints = forces

mGui = Tk()
mass = DoubleVar()
acceleration = DoubleVar()

mGui.title('Simple Newton Gui')

menubar = Menu (mGui)
graphmenu = Menu (mGui)

filemenu = Menu(menubar)
filemenu.add_command(label="First Gui option"""", command = secondGui""")
filemenu.add_command(label="Second Gui option")
filemenu.add_command(label="Third Gui option")
filemenu.add_command(label="Fourth Gui option")
menubar.add_cascade(label="Gui sub menus",menu = filemenu)

graphmenu.add_command(label="Graph this as a slope!",command = mGraphAction)
graphmenu.add_command(label="Graph Gui",command = secondGui)
graphmenu.add_command(label="Third Graph option")
graphmenu.add_command(label="Fourth Graph option")
menubar.add_cascade(label="Graph options",menu = graphmenu)


mlabel = Label(text='Input the Mass please.', fg='red').pack()
mEntry = Entry(mGui,textvariable=mass).pack()
mlabel = Label(text='Inupt the Acceleration please.', fg='red').pack()
mEntry2 = Entry(mGui, textvariable=acceleration).pack()
mbutton = Button(text = 'Calculate',command = mCalculate).pack()

I'm not sure how to define the second Gui, also while I'm here, I would like to take the output from the two inputs and append it into a list where every time the user clicks 'Calculate', you would get number++ ie. user input 12.5, user input 2.0, output = 25.0... [1, 25.0] then another input of 13.5, input 2.0, ouput 27.0... [1,25.0,2,27.0] etc. I would like to know if this kind of appending is possible, or if there's a better way to do it.

1 Year
Discussion Span
Last Post by Brandon Hatch
Featured Replies
  • 2

    You need to create a `Toplevel` window. There is a good example in the famous blog [Mouse vs Python](http://www.blog.pythonlibrary.org/2012/07/26/tkinter-how-to-show-hide-a-window/). Also study how Mike Driscoll uses of a `class App` in this example, in order to encapsulate tkinter code. The example was written for python 2, but it shouldn't be too … Read More


You need to create a Toplevel window. There is a good example in the famous blog Mouse vs Python.

Also study how Mike Driscoll uses of a class App in this example, in order to encapsulate tkinter code.

The example was written for python 2, but it shouldn't be too difficult to adapt it to python 3.

Edited by Gribouillis


Thank you very much, that solves the whole multiple frames problem, but I am still wondering if the appending stated above is possible.


I dont understand how you want to get this user input, nor why it could not be possible to append values to a list. You only need to define a global list and call its append() method when needed.


Ok, so i have everything good to go, except I'm working on the appending thing, and everything works except my counter. Both my force and counter correctly get appended to the list like I want them, but instead of going up by 1 each time i press calculate, the number stays at a constant 1. Here's the part where i define the list and counter.

        self.counter = Tk.IntVar()
        self.forcelist = []

This is the calculate code.

    def mCalculate(self, *arg):
        self.force_string.set( 'Force = Mass * Acceleration = {:4.2f}'.format( self.mass_double.get() * self.acceleration.get() ) )
        self.forcelist.append(self.counter.get() + 1)

if you want the full code just let me know, or if you can spot the error from this, that'd be great.


Nevermind, i figured it out. i used

self.counter.set(self.counter.get() + 1)

and it worked!

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.