self.cvo1 = OptionMenu(root, cvagt_val, *cvagt_list, command=self.comp_gt_data)
self.cvo1.pack()
def comp_gt_data(self, *args):
if cvagt_val.get()!=0:
cvagt_val_loop = cvagt_val.get()
for cvagt_loop in range(1, cvagt_val_loop+1):
self.cvad_l0 = Label(root, text="Enter the %d Device Config"% cvagt_loop)
self.cvad_l0.pack()
self.cvad_l1 = Label(root, text="How Many D~S You Want To Create: ")
self.cvad_l1.pack()
self.cvad_e1 = Entry(root)
self.cvad_e1.pack()
self.cvad_l2 = Label(root, text="How Many MS You Want To Create: ")
self.cvad_l2.pack()
self.cvad_e2 = Entry(root)
self.cvad_e2.pack()
self.cvad_l3 = Label(root, text="How Many SD You Want To Create: ")
self.cvad_l3.pack()
self.cvad_e3 = Entry(root)
self.cvad_e3.pack()
if cvagt_loop < cvagt_val_loop:
if not (self.cv_next_dev_cfg_button):
self.cv_next_dev_cfg_button = Button(root, text="Enter Next Device Configuration", command=self.cv_next_dev_cfg_button_code)
self.cv_next_dev_cfg_button.pack()
# Waiting For cvadt_val_loop_exit bit to get set when the cv_next_dev_cfg_button is clicked but its not happening and circulating in the while loop
cvadt_val_loop_exit = 1
while(cvadt_val_loop_exit):
print "Waiting For Next Device Config Button To Be Hit"
time.sleep(60)
else:
self.cv_next_dev_cfg_button_code()
if not (self.return_button):
self.return_button = Button(root, text="Return To Main Menu", command=self.return_button_code)
self.return_button.pack()
else:
print "Choose Atleast One Device To Create"
def cv_next_dev_cfg_button_code(self):
if (self.cvad_l0):
self.cvad_l0.pack_forget(); self.cvad_l0.destroy(); self.cvad_l0 = None
if (self.cvad_l1):
self.cvad_l1.pack_forget(); self.cvad_l1.destroy(); self.cvad_l1 = None
if (self.cvad_l2):
self.cvad_l2.pack_forget(); self.cvad_l2.destroy(); self.cvad_l2 = None
if (self.cvad_l3):
self.cvad_l3.pack_forget(); self.cvad_l3.destroy(); self.cvad_l3 = None
if (self.cvad_e1):
self.cvad_e1.pack_forget(); self.cvad_e1.destroy(); self.cvad_e1 = None
if (self.cvad_e2):
self.cvad_e2.pack_forget(); self.cvad_e2.destroy(); self.cvad_e2 = None
if (self.cvad_e3):
self.cvad_e3.pack_forget(); self.cvad_e3.destroy(); self.cvad_e3 = None
if (self.cv_next_agt_cfg_button):
self.cv_next_agt_cfg_button.pack_forget(); self.cv_next_agt_cfg_button.destroy(); self.cv_next_agt_cfg_button = None
cvadt_val_loop_exit = 0
答案 0 :(得分:0)
for()不是这里的答案。而是将函数调用正确的次数,并等待多长时间。这应该足以让你开始。
try:
import Tkinter as tk ## Python 2.x
except ImportError:
import tkinter as tk ## Python 3.x
class ButtonForLoop():
def __init__(self, top):
self.top=top
self.but_1=tk.Button(top, text="Start for()", command=self.start_for)
self.but_1.grid(row=0, column=0)
self.num_for=0
## for simplicity, assume 3 iterations through the loop
self.max_num=3
def next_pass(self):
## create button again
self.but_1=tk.Button(top, text="Pass # %d" % (self.num_for),
command=self.start_for)
self.but_1.grid(row=0, column=0)
def start_for(self):
""" button clicked so call next_pass() the correct
number of iterations
"""
## destroy whatever button is showing
self.but_1.destroy()
if self.num_for < self.max_num:
self.num_for += 1
self.top.after(500, self.next_pass)
else:
self.top.quit()
top=tk.Tk()
BF=ButtonForLoop(top)
top. mainloop()