2016-08-26 20 views
1

我是一名初学者python编码人员,我正在尝试制作一个GUI,您可以在其中输入多个学期的信息。一旦用户输入了学期数,我想单独询问每个学期,但是当我使用循环来做到这一点时,所有窗口都立即打开。有没有办法将它们放入一个序列中?如何通过循环制作多个窗口?

这是我迄今为止

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

回答

0

像这样的东西应该让你对你的方式:

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() 

让我知道你在想什么!

+0

谢谢!我没有一定数量的窗口,但使用另一个函数来提高帧,因为你修复了我遇到的问题! – user6763008