我正在尝试创建一个“添加”按钮,在单击该按钮时会添加一个新的输入字段和一个标签。 Tkinter有可能吗?
到目前为止,我已经尝试创建一个仅包含字符串的列表,以便可以将它们用作变量名。然后,我只是计划增加一个num变量,以便下次单击该按钮时它会转到新的列表索引。这是我的代码:
segNums = ['meeting2','meeting3','meeting4','meeting5','meeting6','meeting7','meeting8','meeting9','meeting10']
num = 1
class meetingGUI:
def __init__(self):
self.main_window = tkinter.Tk()
self.main_window.title('Meeting Mailer')
self.meeting_frame = tkinter.Frame(self.main_window)
self.button_frame = tkinter.Frame(self.main_window)
self.meeting_label = tkinter.Label(self.meeting_frame, text='Meeting Segment:')
self.meeting_entry = tkinter.Entry(self.meeting_frame, width=30)
self.meeting_label.pack(side='left')
self.meeting_entry.pack(side='left')
self.add_button = tkinter.Button(self.button_frame, text='Add Segment', command=self.add_seg)
self.quit_button = tkinter.Button(self.button_frame, text='Quit', command=self.main_window.destroy)
self.add_button.pack(side='left')
self.quit_button.pack(side='left')
self.meeting_frame.pack()
self.button_frame.pack()
tkinter.mainloop()
def add_seg(self):
self.segNums[num]_frame = tkinter.Frame(self.main_window)
self.meeting_label = tkinter.Label(self.segNums[num]_frame, text='Meeting Segment:')
self.segNums[num]_entry = tkinter.Entry(self.segNums[num]_frame, width=30)
self.meeting_label.pack(side='left')
self.segNums[num]_entry.pack(side='left')
self.segNums[num]_frame.pack()
num = num + 1
meeting_GUI = meetingGUI()
问题是当我尝试运行代码时收到无效的语法错误。它突出显示在add_seg函数下的第一个“ _Frame”,紧接在第一个segNums [num]之后。 Tkinter甚至有可能吗?