tkinter 一排Label&Entry 或者按鈕其他的 代碼如何精簡
self.TlSet = tk.Toplevel()for labrowSet,labtxtSet in [[0,'1111:'], [1,'2222:'], [2,'3333:'],[3, '4444:'],\
[4, '5555:'], [5, '6666:']]:
tk.Label(self.TlSet, text=labtxtSet).grid(row = labrowSet, column = 0, sticky = 'w')
# for etyrowSet in range(6):
# tk.Entry(self.TlSet).grid(row = etyrowSet, column = 1, sticky = 'w')
self.e1 = StringVar()
self.e2 = StringVar()
self.e3 = StringVar()
self.e4 = StringVar()
self.e5 = StringVar()
self.e6 = StringVar()
self.ety1 = tk.Entry(self.TlSet,textvariable=self.e1)
self.ety2 = tk.Entry(self.TlSet,textvariable=self.e2)
self.ety3 = tk.Entry(self.TlSet,textvariable=self.e3)
self.ety4 = tk.Entry(self.TlSet,textvariable=self.e4)
self.ety5 = tk.Entry(self.TlSet,textvariable=self.e5)
self.ety6 = tk.Entry(self.TlSet,textvariable=self.e6)
self.e1.set('0')
self.e2.set('0')
self.e3.set('0')
self.e4.set('0')
self.e5.set('0')
self.e6.set('0')
self.ety1.grid(row = 0, column = 1, sticky = 'w')
self.ety2.grid(row = 1, column = 1, sticky = 'w')
self.ety3.grid(row = 2, column = 1, sticky = 'w')
self.ety4.grid(row = 3, column = 1, sticky = 'w')
self.ety5.grid(row = 4, column = 1, sticky = 'w')
self.ety6.grid(row = 5, column = 1, sticky = 'w')
self.setbtn = tk.Button(self.TlSet, text='set', command=self.SetDataToSend)
self.setbtn.grid(row = 6, column = 1, sticky = 's'+'e')
self.TakeItCenter()
mytest.Log('Click Set')
主要看那一排排。。其他的無視,怎麼用for循環來精簡代碼呢,不然這代碼看著好憂傷啊!!!