python - 如何在 python 的 Tkinter GUI 中显示完整的文本?
问题描述
我正在创建一个项目,通过按下按钮,来自另一个函数的文本将出现在 GUI 下该按钮下。
文本是保存在列表中的函数结果。
我想在 GUI 窗口中显示全文,如果不能在小窗口中显示,请继续换行以自动适应
到目前为止,我已经尝试在 Label.grid 中显示结果,但我可以粗略地看到我文本的前半句。我还更改了 ipadx 和 ipady 的值,但这不是我想要的,因为它垂直显示所有句子,直到全部显示
from tkinter import *
import tkinter as tk
from tkinter.messagebox import *
global my_list
my_list = ["This is the first sentence , ", "This is the second sentence ,", "this is the third sentence ,", "this is the last sentence "]
def show_answer():
Ans = my_list
blank.insert(0, Ans)
main = Tk()
main.title('Programm')
main.geometry('500x500+300+100')
Button(main, text='Show', command=show_answer).grid(row=30, column=1, sticky=W, pady=4)
Label(main, text="The text is").grid(row=2)
blank = Entry(main)
blank.grid(row=2, column=1, ipadx=50, ipady=50, sticky="NW")
mainloop()
解决方案
您应该使用 tkinter.Text()。
例子 :
text_box = tkinter.Text(parent)
text_box.insert(tkinter.END, "some text...")
这将显示文本并在太长时换行。
推荐阅读
- reactjs - react-bootstrap popover 没有显示(虽然工具提示没问题)
- python - 从另一个数据框列创建新数据框时出错
- java - HashMap vs 数组搜索时间复杂度
- python - 如何在 Instagram 上刮点赞
- java - 如何在 spark submit 命令中将多个 -D 参数传递给 driver-java-options
- docker - 无法使用 docker hub 上的私有 repo 验证 kubernetes 机密,所以我无法部署
- c# - 使用 c# 在运行时文本 HTML 生成中将图像插入 img 标签
- ios - 从 JSON 获取对象
- php - 在 WooCommerce 的订单编辑页面上显示自定义字段
- javascript - javascript:尽管启用了cors,但拒绝访问跨域对象上的属性的权限