How to make multiple windows through a loop?
<p>I'm a beginner python coder and I'm trying to make a GUI where you can enter information for multiple semesters. Once the user inputs the number of semesters, I want to ask about each semester individually but when I use a loop to do this, all of the windows open at once. Is there a way to put them into a sequence?</p>

<p>this is what I have so far</p>

<pre><code>def createSemesterWin(self, numSemesters):
    for x in range(numSemesters):
        semesterWin = Toplevel()
        semesterg = SemesterGUI(semesterWin, x+1)
        semesterWin.mainloop
</code></pre>

<p>Something like this should get you on your way:</p>

<pre><code>from Tkinter import *

## Define root and geometry
root = Tk()
root.geometry('200x200')

# Define Frames
win1, win2, win3 = Frame(root, bg='red'), Frame(root, bg='green'), Frame(root, bg='blue')

# Configure Rows
root.grid_rowconfigure(0, weight = 1)
root.grid_columnconfigure(0, weight = 1)

# Place Frames
for window in [win1, win2, win3]:
    window.grid(row=0, column = 0, sticky = 'news')

# Raises first window 'To the top'
win1.tkraise()

# Function to raise 'window' to the top
def raise_frame(window):
    window.tkraise()

# Page1 label / button
l1 = Label(win1, text = 'This is Page1').pack(side=TOP)
P1 = Button(win1, text = 'Next Page', command = lambda:raise_frame(win2)).pack(side=BOTTOM)

# Page2 label / button
l2 = Label(win2, text = 'This is Page2').pack(side=TOP)
p2 = Button(win2, text = 'Next Page', command = lambda:raise_frame(win3)).pack(side=BOTTOM)

# Page3 label / button
l3 = Label(win3, text = 'This is Page3').pack(side=TOP)
p3 = Button(win3, text = 'Next Page', command = lambda:raise_frame(win1)).pack(side=BOTTOM)

root.mainloop()
</code></pre>

<p>Let me know what you think!</p>

python tkinter