我正在使用Python 2.7并使用tkinter使用循环生成多个条目.... 它只生成一个条目...... 请帮忙。
from Tkinter import *
top = Tk()
top.title('Software')
def button():
top=Tk()
for x in range(1,5):
Label(top,text="Enter:").grid(row=0, column=0, sticky='e')
Entry(top).grid(row=0,column=1,padx=2,pady=2,sticky='we',columnspan=9)
return
Button(top, text="Next", command=button).grid(row=0, column=10, sticky='ew', padx=2,
pady=2)
top.mainloop()
答案 0 :(得分:0)
from Tkinter import *
top = Tk()
top.title('Loop works')
Button( top, text = "Next" ).grid( row = 0, column = 10, sticky = 'ew', \
padx = 2, \
pady = 2 \
)
aProxy = [] # .NEW <Stack> of Access Methods / Wrappers
for x in range( 1, 5 ): # for(){}-looper - - - - - - - - - - - - - -
aProxy.append( StringVar() ) # PUSH an Access Method / Wrapper on <Stack>
aProxy[-1].set( str( -1 * x ) ) # .SET ( asString ) via an Access Method
Label( top, text = "Enter:" ).grid( row = x, column = 0, sticky = 'e' )
Entry( top, textvariable = aProxy[-1] ).grid( row = x, column = 1, sticky = 'we', \
padx = 2, \
pady = 2, \
columnspan = 9
)
pass # - - - - - - - - - - - - - - - - - - - - - -
top.lift() # Tk-GUI-MVC-Visual-Part ensure visibility
top.mainloop() # Tk-GUI-MVC-Controller-Part Entry Point