当我在Tkinter中使用Text Widget时,按钮从GUI窗体中消失

时间:2018-03-10 10:14:00

标签: python python-3.x tkinter

当我在行“inputs = Entry(row)”中使用Entry Widget时,输出表单只能采用单个字符串,因为我更新代码以使用Text Wiget “inputs = Text(row)”输出表单接受多行字符串输入,但按钮消失,请帮助不确定为什么按钮消失

from tkinter import *
fields = 'Section1','Section2'    

def fetch(entries):
   for entry in entries:
      field = entry[0]
      text  = entry[1].get()
      print('%s \n%s\n' % ("\n====================================\n" + field + "\n====================================\n", text))    

def makeform(root, fields):
   entries = []
   for field in fields:
      row = Frame(root)
      labels = Label(row, width=35, text=field, anchor='w')
      inputs = Entry(row) # This is the line where i tried Text Widget
      row.pack(side=TOP, fill=X, padx=15, pady=15)
      labels.pack(side=LEFT)
      inputs.pack(side=RIGHT, expand=YES, fill=X)
      entries.append((field, inputs))
   return entries

if __name__ == '__main__':
   root = Tk()
   root.title('Form')
   entries = makeform(root, fields)
   root.bind('<Return>', (lambda event, e=entries: fetch(e)))
   b1 = Button(root, text='Generate', command=(lambda e=entries: fetch(e)))
   b1.pack(side=LEFT, padx=5, pady=5)
   b2 = Button(root, text='Quit', command=root.quit)
   b2.pack(side=LEFT, padx=5, pady=5)
   root.mainloop()

1 个答案:

答案 0 :(得分:0)

限制Text小部件的高度解决了这个问题。

inputs = Text(row, height=10)