当我在 Tkinter 中使用 Text Widget 时,按钮从 GUI 表单中消失 [英] Buttons disappear form the GUI Form when i use Text Widget in Tkinter

查看:33
本文介绍了当我在 Tkinter 中使用 Text Widget 时,按钮从 GUI 表单中消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When i use Entry Widget in line "inputs = Entry(row)" the output form can only take single string, as soon i update the code to use Text Wiget "inputs = Text(row)" the output form accepts multi line string inputs but the buttons disappear, Please help not sure why the buttons disappear

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()

推荐答案

限制文本小部件的高度解决了该问题.

Restricting the height of the Text widgets resolved the issue.

inputs = Text(row, height=10)

这篇关于当我在 Tkinter 中使用 Text Widget 时,按钮从 GUI 表单中消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆